@johnoscott/isometric-engine 0.0.0-stage → 0.9.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 (310) hide show
  1. package/EDITOR-GUIDE.md +317 -0
  2. package/LICENSE +21 -0
  3. package/LICENSES/ajv.txt +22 -0
  4. package/LICENSES/lucide-static.txt +43 -0
  5. package/LICENSES/yaml.txt +13 -0
  6. package/README.md +62 -2
  7. package/assets/app.css +265 -0
  8. package/assets/default-theme.yaml +99 -0
  9. package/assets/icons.svg +1 -0
  10. package/assets/marks.css +35 -0
  11. package/assets/skin.css +181 -0
  12. package/iso-editor.d.ts +4 -0
  13. package/iso-editor.js +550 -0
  14. package/iso-render.d.ts +3 -0
  15. package/iso-render.js +388 -0
  16. package/iso-systems.d.ts +4 -0
  17. package/iso-systems.js +389 -0
  18. package/js/iso-core/compile-schema.js +22 -0
  19. package/js/iso-core/depth.js +55 -0
  20. package/js/iso-core/errors.js +65 -0
  21. package/js/iso-core/glyphs.js +100 -0
  22. package/js/iso-core/index.js +55 -0
  23. package/js/iso-core/kernel.js +158 -0
  24. package/js/iso-core/metrics.json +1 -0
  25. package/js/iso-core/package.json +6 -0
  26. package/js/iso-core/parse.js +79 -0
  27. package/js/iso-core/schema-errors.js +170 -0
  28. package/js/iso-core/shims/crypto.js +125 -0
  29. package/js/iso-core/shims/path.js +49 -0
  30. package/js/iso-core/svg-dom.js +144 -0
  31. package/js/iso-core/theme.js +48 -0
  32. package/js/iso-core/vdom.js +48 -0
  33. package/js/iso-editor/adapter.js +0 -0
  34. package/js/iso-editor/clipboard.js +152 -0
  35. package/js/iso-editor/commands.js +173 -0
  36. package/js/iso-editor/complete.js +55 -0
  37. package/js/iso-editor/doc.js +182 -0
  38. package/js/iso-editor/index.js +105 -0
  39. package/js/iso-editor/model.js +210 -0
  40. package/js/iso-editor/outline.js +111 -0
  41. package/js/iso-editor/package.json +6 -0
  42. package/js/iso-editor/path.js +19 -0
  43. package/js/iso-editor/providers.js +96 -0
  44. package/js/iso-editor/schema-nav.js +117 -0
  45. package/js/iso-editor/splice.js +441 -0
  46. package/js/iso-editor/storage-keys.js +6 -0
  47. package/js/iso-editor/ui/actions.js +116 -0
  48. package/js/iso-editor/ui/canvas-layer.js +0 -0
  49. package/js/iso-editor/ui/canvas.js +1205 -0
  50. package/js/iso-editor/ui/clip.js +133 -0
  51. package/js/iso-editor/ui/dialog.js +26 -0
  52. package/js/iso-editor/ui/flat-canvas.js +54 -0
  53. package/js/iso-editor/ui/icons.js +15 -0
  54. package/js/iso-editor/ui/keys.js +26 -0
  55. package/js/iso-editor/ui/later.js +28 -0
  56. package/js/iso-editor/ui/layer.js +11 -0
  57. package/js/iso-editor/ui/menu.js +105 -0
  58. package/js/iso-editor/ui/monaco-entry.js +2 -0
  59. package/js/iso-editor/ui/mount-kit.js +0 -0
  60. package/js/iso-editor/ui/mount.js +767 -0
  61. package/js/iso-editor/ui/pane.js +0 -0
  62. package/js/iso-editor/ui/part.js +0 -0
  63. package/js/iso-editor/ui/plain-icons.js +34 -0
  64. package/js/iso-editor/ui/props.js +314 -0
  65. package/js/iso-editor/ui/scope-css.js +81 -0
  66. package/js/iso-editor/ui/setup.js +145 -0
  67. package/js/iso-editor/ui/text.js +323 -0
  68. package/js/iso-editor/ui/tree.js +728 -0
  69. package/js/iso-editor/validate.js +33 -0
  70. package/js/iso-editor/window/protocol.js +8 -0
  71. package/js/iso-objects/assemble.js +43 -0
  72. package/js/iso-objects/assets.js +88 -0
  73. package/js/iso-objects/board.js +162 -0
  74. package/js/iso-objects/compile.js +60 -0
  75. package/js/iso-objects/css.js +154 -0
  76. package/js/iso-objects/flat.js +696 -0
  77. package/js/iso-objects/focus.js +16 -0
  78. package/js/iso-objects/geometry.js +76 -0
  79. package/js/iso-objects/index.js +93 -0
  80. package/js/iso-objects/kinds.js +12 -0
  81. package/js/iso-objects/labels.js +325 -0
  82. package/js/iso-objects/package.json +6 -0
  83. package/js/iso-objects/place.js +347 -0
  84. package/js/iso-objects/route.js +461 -0
  85. package/js/iso-objects/scene.js +350 -0
  86. package/js/iso-objects/steps.js +246 -0
  87. package/js/iso-objects/types.js +0 -0
  88. package/js/iso-systems/catalog.js +42 -0
  89. package/js/iso-systems/compile.js +34 -0
  90. package/js/iso-systems/css.js +8 -0
  91. package/js/iso-systems/index.js +16 -0
  92. package/js/iso-systems/nodes.js +124 -0
  93. package/js/iso-systems/package.json +6 -0
  94. package/js/iso-systems/schema.json +311 -0
  95. package/js/iso-systems/validate.js +35 -0
  96. package/js/iso-viewer/bundle.js +20 -0
  97. package/js/iso-viewer/card-motion.js +228 -0
  98. package/js/iso-viewer/dom.js +14 -0
  99. package/js/iso-viewer/dual-view.js +212 -0
  100. package/js/iso-viewer/flat-view.js +124 -0
  101. package/js/iso-viewer/history.js +990 -0
  102. package/js/iso-viewer/index.js +98 -0
  103. package/js/iso-viewer/morph.js +192 -0
  104. package/js/iso-viewer/overlay.js +199 -0
  105. package/js/iso-viewer/package.json +6 -0
  106. package/js/iso-viewer/page.js +138 -0
  107. package/js/iso-viewer/player.js +409 -0
  108. package/js/iso-viewer/still.js +81 -0
  109. package/js/iso-viewer/timeline-contract.js +14 -0
  110. package/js/iso-viewer/timeline-engine.js +475 -0
  111. package/js/iso-viewer/timeline-export.js +36 -0
  112. package/js/iso-viewer/timeline-scale.js +116 -0
  113. package/js/iso-viewer/timeline-scope.js +58 -0
  114. package/js/iso-viewer/timeline-search.js +216 -0
  115. package/js/iso-viewer/timeline-time.js +55 -0
  116. package/js/iso-viewer/view-css.js +68 -0
  117. package/js/iso-viewer/viewport.js +177 -0
  118. package/package.json +502 -4
  119. package/src/iso-core/compile-schema.ts +23 -0
  120. package/src/iso-core/depth.ts +56 -0
  121. package/src/iso-core/errors.ts +73 -0
  122. package/src/iso-core/glyphs.ts +108 -0
  123. package/src/iso-core/index.ts +27 -0
  124. package/src/iso-core/kernel.ts +163 -0
  125. package/src/iso-core/metrics.json +1 -0
  126. package/src/iso-core/package.json +6 -0
  127. package/src/iso-core/parse.ts +91 -0
  128. package/src/iso-core/schema-errors.ts +163 -0
  129. package/src/iso-core/shims/crypto.ts +37 -0
  130. package/src/iso-core/shims/path.ts +24 -0
  131. package/src/iso-core/svg-dom.ts +103 -0
  132. package/src/iso-core/theme.ts +64 -0
  133. package/src/iso-core/vdom.ts +41 -0
  134. package/src/iso-editor/adapter.ts +128 -0
  135. package/src/iso-editor/clipboard.ts +163 -0
  136. package/src/iso-editor/commands.ts +191 -0
  137. package/src/iso-editor/complete.ts +73 -0
  138. package/src/iso-editor/doc.ts +207 -0
  139. package/src/iso-editor/index.ts +67 -0
  140. package/src/iso-editor/model.ts +234 -0
  141. package/src/iso-editor/outline.ts +126 -0
  142. package/src/iso-editor/package.json +6 -0
  143. package/src/iso-editor/path.ts +18 -0
  144. package/src/iso-editor/providers.ts +113 -0
  145. package/src/iso-editor/schema-nav.ts +129 -0
  146. package/src/iso-editor/splice.ts +472 -0
  147. package/src/iso-editor/storage-keys.ts +6 -0
  148. package/src/iso-editor/ui/actions.ts +119 -0
  149. package/src/iso-editor/ui/app.css +230 -0
  150. package/src/iso-editor/ui/canvas-layer.ts +56 -0
  151. package/src/iso-editor/ui/canvas.ts +1071 -0
  152. package/src/iso-editor/ui/clip.ts +97 -0
  153. package/src/iso-editor/ui/dialog.ts +25 -0
  154. package/src/iso-editor/ui/flat-canvas.ts +51 -0
  155. package/src/iso-editor/ui/icons.ts +21 -0
  156. package/src/iso-editor/ui/keys.ts +30 -0
  157. package/src/iso-editor/ui/later.ts +22 -0
  158. package/src/iso-editor/ui/layer.ts +7 -0
  159. package/src/iso-editor/ui/marks.css +35 -0
  160. package/src/iso-editor/ui/menu.ts +67 -0
  161. package/src/iso-editor/ui/monaco-entry.ts +6 -0
  162. package/src/iso-editor/ui/mount-kit.ts +35 -0
  163. package/src/iso-editor/ui/mount.ts +684 -0
  164. package/src/iso-editor/ui/pane.ts +45 -0
  165. package/src/iso-editor/ui/part.ts +45 -0
  166. package/src/iso-editor/ui/plain-icons.ts +83 -0
  167. package/src/iso-editor/ui/props.ts +347 -0
  168. package/src/iso-editor/ui/scope-css.ts +65 -0
  169. package/src/iso-editor/ui/setup.ts +144 -0
  170. package/src/iso-editor/ui/skin.css +181 -0
  171. package/src/iso-editor/ui/text.ts +262 -0
  172. package/src/iso-editor/ui/tree.ts +657 -0
  173. package/src/iso-editor/validate.ts +62 -0
  174. package/src/iso-editor/window/protocol.ts +33 -0
  175. package/src/iso-objects/assemble.ts +57 -0
  176. package/src/iso-objects/assets.ts +122 -0
  177. package/src/iso-objects/board.ts +169 -0
  178. package/src/iso-objects/compile.ts +76 -0
  179. package/src/iso-objects/css.ts +163 -0
  180. package/src/iso-objects/flat.ts +653 -0
  181. package/src/iso-objects/focus.ts +14 -0
  182. package/src/iso-objects/geometry.ts +86 -0
  183. package/src/iso-objects/index.ts +33 -0
  184. package/src/iso-objects/kinds.ts +56 -0
  185. package/src/iso-objects/labels.ts +310 -0
  186. package/src/iso-objects/package.json +6 -0
  187. package/src/iso-objects/place.ts +318 -0
  188. package/src/iso-objects/route.ts +444 -0
  189. package/src/iso-objects/scene.ts +376 -0
  190. package/src/iso-objects/steps.ts +234 -0
  191. package/src/iso-objects/types.ts +68 -0
  192. package/src/iso-systems/catalog.ts +31 -0
  193. package/src/iso-systems/compile.ts +39 -0
  194. package/src/iso-systems/css.ts +9 -0
  195. package/src/iso-systems/index.ts +12 -0
  196. package/src/iso-systems/nodes.ts +126 -0
  197. package/src/iso-systems/package.json +6 -0
  198. package/src/iso-systems/schema.json +311 -0
  199. package/src/iso-systems/validate.ts +34 -0
  200. package/src/iso-viewer/bundle.ts +15 -0
  201. package/src/iso-viewer/card-motion.ts +237 -0
  202. package/src/iso-viewer/dom.ts +13 -0
  203. package/src/iso-viewer/dual-view.ts +212 -0
  204. package/src/iso-viewer/flat-view.ts +127 -0
  205. package/src/iso-viewer/history.ts +781 -0
  206. package/src/iso-viewer/index.ts +40 -0
  207. package/src/iso-viewer/morph.ts +191 -0
  208. package/src/iso-viewer/overlay.ts +212 -0
  209. package/src/iso-viewer/package.json +6 -0
  210. package/src/iso-viewer/page.ts +150 -0
  211. package/src/iso-viewer/player.ts +321 -0
  212. package/src/iso-viewer/still.ts +74 -0
  213. package/src/iso-viewer/timeline-contract.ts +342 -0
  214. package/src/iso-viewer/timeline-engine.ts +420 -0
  215. package/src/iso-viewer/timeline-export.ts +31 -0
  216. package/src/iso-viewer/timeline-scale.ts +129 -0
  217. package/src/iso-viewer/timeline-scope.ts +56 -0
  218. package/src/iso-viewer/timeline-search.ts +198 -0
  219. package/src/iso-viewer/timeline-time.ts +54 -0
  220. package/src/iso-viewer/view-css.ts +59 -0
  221. package/src/iso-viewer/viewport.ts +142 -0
  222. package/types/iso-core/compile-schema.d.ts +11 -0
  223. package/types/iso-core/depth.d.ts +6 -0
  224. package/types/iso-core/errors.d.ts +24 -0
  225. package/types/iso-core/glyphs.d.ts +19 -0
  226. package/types/iso-core/index.d.ts +17 -0
  227. package/types/iso-core/kernel.d.ts +130 -0
  228. package/types/iso-core/metrics.json +1 -0
  229. package/types/iso-core/parse.d.ts +18 -0
  230. package/types/iso-core/schema-errors.d.ts +14 -0
  231. package/types/iso-core/shims/crypto.d.ts +9 -0
  232. package/types/iso-core/svg-dom.d.ts +15 -0
  233. package/types/iso-core/theme.d.ts +38 -0
  234. package/types/iso-core/vdom.d.ts +26 -0
  235. package/types/iso-editor/adapter.d.ts +145 -0
  236. package/types/iso-editor/clipboard.d.ts +23 -0
  237. package/types/iso-editor/commands.d.ts +32 -0
  238. package/types/iso-editor/complete.d.ts +25 -0
  239. package/types/iso-editor/doc.d.ts +50 -0
  240. package/types/iso-editor/index.d.ts +57 -0
  241. package/types/iso-editor/model.d.ts +96 -0
  242. package/types/iso-editor/outline.d.ts +28 -0
  243. package/types/iso-editor/path.d.ts +7 -0
  244. package/types/iso-editor/providers.d.ts +43 -0
  245. package/types/iso-editor/schema-nav.d.ts +34 -0
  246. package/types/iso-editor/splice.d.ts +53 -0
  247. package/types/iso-editor/storage-keys.d.ts +5 -0
  248. package/types/iso-editor/ui/actions.d.ts +23 -0
  249. package/types/iso-editor/ui/canvas-layer.d.ts +65 -0
  250. package/types/iso-editor/ui/canvas.d.ts +279 -0
  251. package/types/iso-editor/ui/clip.d.ts +14 -0
  252. package/types/iso-editor/ui/dialog.d.ts +7 -0
  253. package/types/iso-editor/ui/flat-canvas.d.ts +2 -0
  254. package/types/iso-editor/ui/icons.d.ts +5 -0
  255. package/types/iso-editor/ui/keys.d.ts +7 -0
  256. package/types/iso-editor/ui/later.d.ts +12 -0
  257. package/types/iso-editor/ui/layer.d.ts +2 -0
  258. package/types/iso-editor/ui/menu.d.ts +21 -0
  259. package/types/iso-editor/ui/mount-kit.d.ts +31 -0
  260. package/types/iso-editor/ui/mount.d.ts +146 -0
  261. package/types/iso-editor/ui/pane.d.ts +60 -0
  262. package/types/iso-editor/ui/part.d.ts +40 -0
  263. package/types/iso-editor/ui/plain-icons.d.ts +10 -0
  264. package/types/iso-editor/ui/props.d.ts +57 -0
  265. package/types/iso-editor/ui/scope-css.d.ts +5 -0
  266. package/types/iso-editor/ui/setup.d.ts +40 -0
  267. package/types/iso-editor/ui/text.d.ts +19 -0
  268. package/types/iso-editor/ui/tree.d.ts +100 -0
  269. package/types/iso-editor/validate.d.ts +36 -0
  270. package/types/iso-editor/window/protocol.d.ts +60 -0
  271. package/types/iso-objects/assemble.d.ts +35 -0
  272. package/types/iso-objects/assets.d.ts +49 -0
  273. package/types/iso-objects/board.d.ts +36 -0
  274. package/types/iso-objects/compile.d.ts +35 -0
  275. package/types/iso-objects/css.d.ts +16 -0
  276. package/types/iso-objects/flat.d.ts +130 -0
  277. package/types/iso-objects/focus.d.ts +1 -0
  278. package/types/iso-objects/geometry.d.ts +59 -0
  279. package/types/iso-objects/index.d.ts +26 -0
  280. package/types/iso-objects/kinds.d.ts +53 -0
  281. package/types/iso-objects/labels.d.ts +92 -0
  282. package/types/iso-objects/place.d.ts +25 -0
  283. package/types/iso-objects/route.d.ts +67 -0
  284. package/types/iso-objects/scene.d.ts +63 -0
  285. package/types/iso-objects/steps.d.ts +90 -0
  286. package/types/iso-objects/types.d.ts +140 -0
  287. package/types/iso-systems/catalog.d.ts +4 -0
  288. package/types/iso-systems/compile.d.ts +6 -0
  289. package/types/iso-systems/css.d.ts +3 -0
  290. package/types/iso-systems/index.d.ts +5 -0
  291. package/types/iso-systems/nodes.d.ts +3 -0
  292. package/types/iso-viewer/card-motion.d.ts +56 -0
  293. package/types/iso-viewer/dom.d.ts +1 -0
  294. package/types/iso-viewer/dual-view.d.ts +44 -0
  295. package/types/iso-viewer/flat-view.d.ts +25 -0
  296. package/types/iso-viewer/history.d.ts +91 -0
  297. package/types/iso-viewer/index.d.ts +31 -0
  298. package/types/iso-viewer/morph.d.ts +28 -0
  299. package/types/iso-viewer/overlay.d.ts +135 -0
  300. package/types/iso-viewer/page.d.ts +13 -0
  301. package/types/iso-viewer/still.d.ts +26 -0
  302. package/types/iso-viewer/timeline-contract.d.ts +345 -0
  303. package/types/iso-viewer/timeline-engine.d.ts +20 -0
  304. package/types/iso-viewer/timeline-export.d.ts +5 -0
  305. package/types/iso-viewer/timeline-scale.d.ts +44 -0
  306. package/types/iso-viewer/timeline-scope.d.ts +33 -0
  307. package/types/iso-viewer/timeline-search.d.ts +52 -0
  308. package/types/iso-viewer/timeline-time.d.ts +8 -0
  309. package/types/iso-viewer/view-css.d.ts +7 -0
  310. package/types/iso-viewer/viewport.d.ts +50 -0
@@ -0,0 +1,144 @@
1
+ // An editor set up from a domain adapter alone (R1 S8): the kits every view takes (the tree's, the panel's, the
2
+ // canvas's, the mount's), made from the adapter with plain words, and the three views' features (text, canvas, edit).
3
+ // A domain gives its adapter, how a reading is drawn, its catalogue and theme; anything it says more (its words, its
4
+ // icons, a layer over the canvas, a part beside the views) replaces the plain default. A domain with its own words for
5
+ // every view sets its kits up by hand instead; this is for a domain that wants the editor as it comes.
6
+ //
7
+ // The text pane is given, not imported: Monaco is a big dependency, and a host without it still gets the canvas, the
8
+ // tree and the panel.
9
+
10
+ import type { DomainAdapter, FileRole } from '../adapter.ts';
11
+ import type { Path } from '../path.ts';
12
+ import { toPointer } from '../path.ts';
13
+ import { outline } from '../outline.ts';
14
+ import { commandsFor } from '../commands.ts';
15
+ import { clipboardFor } from '../clipboard.ts';
16
+ import { providersFor, docFor, rangeOfPath } from '../providers.ts';
17
+ import { analyse } from '../validate.ts';
18
+ import type { KindCatalog } from '../../iso-objects/kinds.ts';
19
+ import { actionsFor } from './actions.ts';
20
+ import { clipboard } from './clip.ts';
21
+ import { propsPanel, type PropsKit } from './props.ts';
22
+ import type { TreeKit } from './tree.ts';
23
+ import { canvasView, type CanvasKit, type CanvasDrawing, type CanvasUi } from './canvas.ts';
24
+ import type { CanvasCtx, CanvasLayer } from './canvas-layer.ts';
25
+ import type { MountKit } from './mount-kit.ts';
26
+ import type { EditorSetup, ShellWords, ShellFeatures } from './mount.ts';
27
+ import type { PaneOpts, TextServices } from './pane.ts';
28
+ import type { MonacoPane } from './text.ts';
29
+ import type { IconName } from './icons.ts';
30
+ import { PLAIN_ICON_SVG, iconSymbols, spriteOf } from './plain-icons.ts';
31
+ import type { KeyGroup } from './keys.ts';
32
+ import type { EditorModel } from '../model.ts';
33
+ import type { PartCtx, EditorPart } from './part.ts';
34
+
35
+ type Raw = Record<string, unknown>;
36
+
37
+ /** what a domain gives besides its adapter */
38
+ export interface DomainView<R, D extends CanvasDrawing> {
39
+ /** a reading, drawn (the adapter's read() gives the reading) */
40
+ draw(read: R, data: unknown, theme: string): D;
41
+ catalog: KindCatalog;
42
+ theme: string;
43
+ /** the file's name when the host gives none */
44
+ fileName: string;
45
+ /** what a name must be, and the rule in words */
46
+ nameRule?: RegExp; nameHint?: string;
47
+ /** a kind's icon (default: box) */
48
+ icon?(kind: string): IconName;
49
+ /** the domain's own icons, as 24 × 24 SVG bodies by name (stroke in currentColor, as Lucide's), added to L3's */
50
+ icons?: Record<string, string>;
51
+ words?: Partial<ShellWords>;
52
+ keymap?: KeyGroup[];
53
+ /** the canvas's 2D view (0.6.0): a 3D | 2D switch; its link kinds' styles (the host's canvas CSS adds flatCss) */
54
+ flat?: CanvasKit<R, D>['flat'];
55
+ /** a layer over the canvas, and a part beside the views (A: their calls) */
56
+ layer?(ctx: CanvasCtx<D>): CanvasLayer<object>;
57
+ part?(ctx: PartCtx): EditorPart<object>;
58
+ }
59
+
60
+ const NAME = /^[a-z][a-z0-9-]*$/;
61
+ /** the plain shell's words */
62
+ export const PLAIN_WORDS: ShellWords = {
63
+ rootClass: 'iso-editor', brand: 'iso <b>editor</b>', sideLabel: 'The file', canvasLabel: 'The file, drawn',
64
+ problemsLabel: 'Problems', bottomTabsLabel: 'Problems', extraTab: 'Check', slots: '',
65
+ };
66
+ /** the plain keymap: the shell's own keys */
67
+ export const PLAIN_KEYMAP: KeyGroup[] = [
68
+ { where: 'Anywhere in the editor', keys: [['⌘S', 'Save'], ['⌘Z', 'Undo'], ['⇧⌘Z or ⌘Y', 'Redo'], ['?', 'This sheet'], ['Esc', 'Close a menu or dialog']] },
69
+ { where: 'The tree and the canvas', keys: [['F2', 'Rename'], ['⌫', 'Delete'], ['⌘D', 'Duplicate'], ['⌘↑', 'Select the parent']] },
70
+ { where: 'The canvas', keys: [['+ −', 'Zoom'], ['0', 'Fit'], ['1', '100%'], ['⇧2', 'Zoom to the selection']] },
71
+ ];
72
+
73
+ /** The kits and features for an adapter (R: its reading; D: its drawing), with the text pane if the host has one. */
74
+ export function setupFor<R, D extends CanvasDrawing>(a: DomainAdapter, v: DomainView<R, D>, textPane?: (el: HTMLElement, doc: EditorModel, o: PaneOpts) => MonacoPane): EditorSetup<R, undefined, object> {
75
+ const commands = commandsFor(a);
76
+ const nameRule = v.nameRule ?? NAME, nameHint = v.nameHint ?? 'a lower-case letter, then lower-case letters, digits and -';
77
+ const icon = v.icon ?? (() => 'box' as IconName);
78
+ const actions = actionsFor({ commands, objectOf: a.objectOf, kinds: a.kinds, nameRule, nameHint });
79
+ const P = providersFor(a);
80
+ const services: TextServices = { docFor, completionAt: P.completionAt, hoverAt: P.hoverAt, definitionAt: P.definitionAt, rangeOfPath };
81
+ const getIn = (o: unknown, p: Path) => p.reduce<unknown>((x, k) => (x && typeof x === 'object' ? (x as Raw)[k as string] : undefined), o);
82
+ const layoutUnder = (data: unknown, key: string) => getIn(data, [key, 'layout']) as Raw | undefined;
83
+ const pins = {
84
+ key: a.pins.key, legacyKey: a.pins.legacyKey, legacyOnly: a.pins.legacyOnly,
85
+ of: (data: unknown) => layoutUnder(data, a.pins.key) ?? (a.pins.legacyKey ? layoutUnder(data, a.pins.legacyKey) : undefined),
86
+ keyOf: (data: unknown) => (a.pins.legacyOnly(data) && a.pins.legacyKey ? a.pins.legacyKey : a.pins.key),
87
+ };
88
+ const read = (text: string, fileName = v.fileName) => a.read(text, { fileName, role: a.role(text) });
89
+
90
+ const tree: TreeKit = {
91
+ outline: (d, role, tags) => outline(d, a, role, tags), commands, slotAt: a.slotAt, kinds: a.kinds, entryGroups: a.entryGroups, nameRule,
92
+ ui: {
93
+ label: 'The file, as a tree', rootIcon: 'layers', kindIcon: icon, keyIcon: () => undefined, entryIcon: () => 'list-tree' as IconName,
94
+ newItems: k => { const x = a.kinds.find(y => y.kind === k)!; return [{ label: `New ${x.singular}`, icon: icon(k) }]; },
95
+ tagPill: tag => ({ title: tag }), nameHint,
96
+ text: { root: 'File', rootAdd: 'the file', renameWhy: 'Groups and the file itself have fixed names', deleteWhy: 'The file itself stays', duplicateNote: 'Duplicate works on objects', duplicateWhy: 'Only objects can be duplicated' },
97
+ },
98
+ };
99
+ const props: PropsKit = {
100
+ commands, actions, slotAt: a.slotAt, objectOf: a.objectOf, kinds: a.kinds,
101
+ ui: { important: () => [], isExternal: () => false, inheritedFrom: 'the base file', extensionDoc: 'An extension: ignored by the reader.', rootTitle: 'The file', rootItem: '(the file)' },
102
+ };
103
+ const canvasUi: CanvasUi = {
104
+ rootClass: 'iso-canvas', panKeyClass: 'pan-key', newOrder: a.kinds.map(k => k.kind),
105
+ palette: a.kinds.map(k => ({ kind: k.kind, icon: icon(k.kind), label: k.singular[0].toUpperCase() + k.singular.slice(1) })),
106
+ text: {
107
+ stage: 'The file, drawn: arrow keys and Tab move through what is drawn; + and − zoom, 0 fits', dragGroup: 'A drag on nothing',
108
+ dragSelectTip: 'Drag draws a selection; hold the space key to pan', unreadable: 'The canvas draws a file that reads cleanly; fix the problems listed to see it.',
109
+ palette: 'Add to the file: click, or drag onto the canvas', pinHint: '', renameWhy: 'Only objects are renamed here', duplicateWhy: 'Only objects are duplicated',
110
+ },
111
+ };
112
+ const canvas: CanvasKit<R, D> = {
113
+ draw: v.draw, catalog: v.catalog, objectOf: a.objectOf, kinds: a.kinds, commands, actions, objectItems: () => [], pins, ui: canvasUi, flat: v.flat,
114
+ trial: (text, theme) => { const r = read(text); return r.read === undefined || r.diags.some(d => d.severity === 'error') ? undefined : v.draw(r.read as R, (r.read as { data?: unknown }).data, theme); },
115
+ };
116
+ const kit: MountKit<R, undefined> = {
117
+ async check(text) {
118
+ const r = analyse(a, text, { fileName: v.fileName });
119
+ const ok = !r.problems.some(p => p.severity === 'error') && r.read !== undefined;
120
+ return { problems: r.problems, read: r.read as R | undefined, tags: r.tags, model: ok ? r.read : undefined, data: (r.read as { data?: unknown } | undefined)?.data, extra: undefined };
121
+ },
122
+ role: (text): FileRole => a.role(text),
123
+ kindLabel: () => a.id,
124
+ nav: P.navFor,
125
+ objectPath(name, r) {
126
+ const data = (r as { data?: unknown } | undefined)?.data;
127
+ for (const k of a.kinds) if (getIn(data, [...k.section, name]) !== undefined) return toPointer([...k.section, name]);
128
+ return undefined;
129
+ },
130
+ extraLabel: () => ({ text: '', cls: '' }),
131
+ keymap: v.keymap ?? PLAIN_KEYMAP,
132
+ };
133
+ const features: ShellFeatures & Record<string, unknown> = {
134
+ canvas: { canvasView: (host: HTMLElement, doc: EditorModel, o: never) => canvasView<R, D, object>(host, doc, { ...(o as object), theme: v.theme, kit: canvas, layer: v.layer } as never) },
135
+ edit: { propsPanel: (body: HTMLElement, doc: EditorModel, o: never) => propsPanel(body, doc, { ...(o as object), kit: props } as never), clipboard: (doc: EditorModel, note: (t: string, tone?: 'info' | 'warn' | 'bad') => void) => clipboard(doc, note, clipboardFor(a)) },
136
+ ...(textPane ? { text: { textPane: (el: HTMLElement, doc: EditorModel, o: Omit<PaneOpts, 'services'>) => textPane(el, doc, { ...o, services }) } } : {}),
137
+ };
138
+ return {
139
+ kit, tree, words: { ...PLAIN_WORDS, ...v.words }, features,
140
+ names: ['text', 'canvas', 'edit'], late: ['text'], hasExtra: false,
141
+ part: v.part ? ctx => v.part!(ctx) as EditorPart<object> : undefined,
142
+ sprite: spriteOf(iconSymbols({ ...PLAIN_ICON_SVG, ...v.icons })),
143
+ };
144
+ }
@@ -0,0 +1,181 @@
1
+ /* The editor's plain skin (L3): its tokens, a base, and the blocks the editor's views use (buttons, segmented
2
+ controls, callouts, menus, pills, counts, fields, dialogs). A build that has no skin of its own puts this before
3
+ app.css and scopes both under its root class; a domain's skin replaces it whole, keeping the token names (its
4
+ tokens over these, its blocks over these). Light and dark follow the root's color-scheme, which mountEditor sets
5
+ from the theme (system: the page's), through light-dark(). Neutral greys, one blue accent. */
6
+ @layer tokens, base, components, views;
7
+
8
+ @layer tokens {
9
+ :root {
10
+ color-scheme: light dark;
11
+ /* colours */
12
+ --bg: light-dark(#f6f7f9, #14161a);
13
+ --surface: light-dark(#ffffff, #1b1e23);
14
+ --surface-2: light-dark(#f0f2f5, #22262c);
15
+ --line: light-dark(#dde1e6, #30353d);
16
+ --line-strong: light-dark(#c3c9d1, #444a54);
17
+ --ink: light-dark(#1c2026, #e8eaed);
18
+ --ink-2: light-dark(#4f5762, #b3b9c2);
19
+ --ink-3: light-dark(#7a828d, #868d97);
20
+ --accent: light-dark(#2f6fd6, #6ea2f2);
21
+ --accent-hover: light-dark(#255cb5, #8bb5f5);
22
+ --accent-tint: light-dark(#e6effc, #1f2d44);
23
+ --on-accent: light-dark(#ffffff, #0e1420);
24
+ --ok: light-dark(#1f7a4d, #5fc08d);
25
+ --ok-tint: light-dark(#e5f4ec, #18301f);
26
+ --warn: light-dark(#a35f00, #e2a54a);
27
+ --warn-tint: light-dark(#fbf0df, #34280f);
28
+ --bad: light-dark(#c2362e, #f07a72);
29
+ --bad-tint: light-dark(#fbe7e5, #3a1b19);
30
+ --on-danger: light-dark(#ffffff, #1a0b0a);
31
+ --info: var(--accent);
32
+ --info-tint: var(--accent-tint);
33
+ --focus: light-dark(#2f6fd6, #8bb5f5);
34
+ --state-hover: light-dark(rgb(0 0 0 / .05), rgb(255 255 255 / .06));
35
+ --state-press: light-dark(rgb(0 0 0 / .09), rgb(255 255 255 / .1));
36
+ --scrim: light-dark(rgb(20 24 30 / .35), rgb(0 0 0 / .5));
37
+ --shadow-1: 0 1px 2px light-dark(rgb(0 0 0 / .08), rgb(0 0 0 / .4));
38
+ --shadow-2: 0 4px 12px light-dark(rgb(0 0 0 / .12), rgb(0 0 0 / .5));
39
+ --shadow-3: 0 12px 32px light-dark(rgb(0 0 0 / .18), rgb(0 0 0 / .6));
40
+ /* type */
41
+ --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
42
+ --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
43
+ --fs-xs: 11px; --fs-sm: 12px; --fs-md: 13px; --fs-lg: 15px; --fs-xl: 18px; --fs-mono: 12px;
44
+ --fw-regular: 400; --fw-medium: 500; --fw-strong: 600;
45
+ --lh: 1.45;
46
+ /* sizes */
47
+ --sp-0: 2px; --sp-1: 4px; --sp-2: 6px; --sp-3: 8px; --sp-4: 12px; --sp-5: 16px; --sp-6: 24px;
48
+ --r-xs: 2px; --r-sm: 4px; --r-md: 6px; --r-lg: 8px; --r-xl: 12px; --r-pill: 999px;
49
+ --bw: 1px;
50
+ --ctl-sm: 24px; --ctl-md: 28px; --ctl-lg: 34px; --ctl-px: 10px;
51
+ --title-bar-h: 44px; --status-h: 24px; --tree-indent: 14px;
52
+ --dur-1: .12s; --ease: cubic-bezier(.2, 0, 0, 1);
53
+ --z-menu: 50;
54
+ }
55
+ }
56
+
57
+ @layer base {
58
+ * { box-sizing: border-box; }
59
+ html, body { margin: 0; }
60
+ body { font: var(--fw-regular) var(--fs-md)/var(--lh) var(--font); color: var(--ink); background: var(--bg); }
61
+ a { color: var(--accent); text-decoration: none; }
62
+ a:hover { text-decoration: underline; }
63
+ }
64
+
65
+ @layer components {
66
+ code, kbd, .mono { font-family: var(--mono); font-size: var(--fs-mono); }
67
+ :focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
68
+ input:focus-visible, select:focus-visible, textarea:focus-visible { outline-offset: 0; }
69
+ .icon { width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
70
+
71
+ .btn { display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2); height: var(--ctl-md); padding: 0 var(--ctl-px);
72
+ border: var(--bw) solid var(--line-strong); border-radius: var(--r-md); background: var(--surface); color: var(--ink);
73
+ font: inherit; font-weight: var(--fw-medium); white-space: nowrap; cursor: pointer; transition: background var(--dur-1) var(--ease); }
74
+ .btn:hover { background: var(--surface-2); }
75
+ .btn:active { background: var(--state-press); }
76
+ .btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
77
+ .btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
78
+ .btn.quiet { border-color: transparent; background: none; color: var(--ink-2); }
79
+ .btn.quiet:hover { background: var(--state-hover); color: var(--ink); }
80
+ .btn.quiet:active { background: var(--state-press); }
81
+ .btn.danger { color: var(--bad); }
82
+ .btn.danger:hover { background: var(--bad-tint); }
83
+ .btn.danger.primary { background: var(--bad); border-color: var(--bad); color: var(--on-danger); }
84
+ .btn.danger.primary:hover { background: color-mix(in srgb, var(--bad) 88%, black); }
85
+ .btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: default; pointer-events: none; }
86
+ .btn.danger:disabled, .btn.danger.primary:disabled { opacity: .45; }
87
+ .btn.quiet:disabled { background: none; }
88
+ .btn[aria-busy="true"] { cursor: progress; }
89
+ .btn.sm { height: var(--ctl-sm); padding: 0 var(--sp-2); font-size: var(--fs-sm); }
90
+ .btn .icon { width: 16px; height: 16px; }
91
+ .btn.sm .icon { width: 14px; height: 14px; }
92
+ .btn.lg { height: var(--ctl-lg); padding: 0 var(--sp-5); }
93
+ .btn.icon-only { width: var(--ctl-md); padding: 0; }
94
+ .btn.sm.icon-only { width: var(--ctl-sm); }
95
+ .btn-group { display: inline-flex; }
96
+ .btn-group > .btn { border-radius: 0; }
97
+ .btn-group > .btn:first-of-type { border-radius: var(--r-md) 0 0 var(--r-md); }
98
+ .btn-group > .btn:last-of-type { border-radius: 0 var(--r-md) var(--r-md) 0; }
99
+ .btn-group > .btn:only-of-type { border-radius: var(--r-md); }
100
+ .btn-group > .btn + .btn { margin-left: calc(-1 * var(--bw)); }
101
+ .btn-group > .btn:hover, .btn-group > .btn:focus-visible { position: relative; z-index: 1; }
102
+ .actions { display: flex; gap: var(--sp-2); align-items: center; }
103
+ .spacer { flex: 1; }
104
+
105
+ .segmented { display: inline-flex; padding: var(--sp-0); gap: var(--sp-0); border-radius: var(--r-md); background: var(--surface-2); border: var(--bw) solid var(--line); }
106
+ .seg { display: inline-flex; align-items: center; gap: var(--sp-1); height: calc(var(--ctl-sm) - 2px); padding: 0 var(--sp-3); border: 0; border-radius: var(--r-sm);
107
+ background: none; color: var(--ink-2); font: inherit; font-size: var(--fs-sm); cursor: pointer; }
108
+ .seg .icon { width: 14px; height: 14px; }
109
+ .seg:hover { color: var(--ink); background: var(--state-hover); }
110
+ .seg.active, .seg[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-1); }
111
+ .seg:disabled, .seg[aria-disabled="true"] { opacity: .5; cursor: default; }
112
+
113
+ .callout { display: flex; gap: var(--sp-3); align-items: flex-start; padding: var(--sp-3) var(--sp-4); border: var(--bw) solid var(--line);
114
+ border-radius: var(--r-md); background: var(--surface); color: var(--ink); }
115
+ .callout[hidden] { display: none; }
116
+ .callout > .icon { margin-top: 2px; color: var(--ink-2); }
117
+ .callout .c-body { flex: 1; min-width: 0; }
118
+ .callout .c-body > p { margin: 0; }
119
+ .callout .c-title { font-weight: var(--fw-strong); }
120
+ .callout .c-acts { display: flex; gap: var(--sp-2); }
121
+ .callout .c-acts .btn.quiet { color: inherit; }
122
+ .callout.ok { background: var(--ok-tint); border-color: color-mix(in srgb, var(--ok) 35%, transparent); }
123
+ .callout.ok > .icon { color: var(--ok); }
124
+ .callout.warn { background: var(--warn-tint); border-color: color-mix(in srgb, var(--warn) 35%, transparent); }
125
+ .callout.warn > .icon { color: var(--warn); }
126
+ .callout.bad { background: var(--bad-tint); border-color: color-mix(in srgb, var(--bad) 35%, transparent); }
127
+ .callout.bad > .icon { color: var(--bad); }
128
+ .callout.banner { border-radius: 0; border-width: 0 0 var(--bw); }
129
+ .callout.compact { padding: var(--sp-2) var(--sp-3); font-size: var(--fs-sm); box-shadow: var(--shadow-2); }
130
+ .callout.compact > .icon { margin-top: 1px; width: 14px; height: 14px; }
131
+
132
+ .menu { position: fixed; z-index: var(--z-menu); min-width: 180px; max-width: 360px; padding: var(--sp-1); background: var(--surface);
133
+ border: var(--bw) solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow-3); }
134
+ .menu[hidden] { display: none; }
135
+ .menu-item { display: flex; align-items: center; gap: var(--sp-2); width: 100%; min-height: var(--ctl-sm); padding: var(--sp-1) var(--sp-3);
136
+ border: 0; border-radius: var(--r-sm); background: none; color: var(--ink); font: inherit; text-align: left; cursor: pointer; }
137
+ .menu-item:hover, .menu-item:focus-visible { background: var(--state-hover); outline: none; }
138
+ .menu-item > .icon { width: 14px; height: 14px; color: var(--ink-2); }
139
+ .menu-item > .mi-label { flex: 1; }
140
+ .menu-item .desc { display: block; color: var(--ink-3); font-size: var(--fs-xs); }
141
+ .menu-item.danger { color: var(--bad); }
142
+ .menu-item.danger > .icon { color: var(--bad); }
143
+ .menu-item:disabled { color: var(--ink-3); cursor: default; }
144
+ .menu-item:disabled .desc { color: var(--ink-3); }
145
+ .menu-check { width: 14px; flex: none; color: var(--accent); }
146
+ .menu-sep { height: var(--bw); margin: var(--sp-1) 0; background: var(--line); border: 0; }
147
+
148
+ .pill { display: inline-flex; align-items: center; gap: var(--sp-1); padding: 0 var(--sp-2); border: var(--bw) solid var(--line);
149
+ border-radius: var(--r-pill); font-size: var(--fs-xs); color: var(--ink-2); white-space: nowrap; }
150
+ .pill .icon { width: 12px; height: 12px; }
151
+ .count { display: inline-flex; align-items: center; justify-content: center; min-width: 18px; height: 18px; padding: 0 var(--sp-1);
152
+ border-radius: var(--r-pill); background: var(--surface-2); color: var(--ink-2); font-size: var(--fs-xs); font-weight: var(--fw-medium); }
153
+ .count.warn { background: var(--warn-tint); color: var(--warn); }
154
+ .count.bad { background: var(--bad-tint); color: var(--bad); }
155
+
156
+ .field { display: grid; gap: var(--sp-1); }
157
+ .field > span { font-size: var(--fs-sm); color: var(--ink-2); font-weight: var(--fw-medium); }
158
+ .field small { color: var(--ink-3); font-size: var(--fs-xs); }
159
+ .field[hidden] { display: none; }
160
+ .field.check { grid-template-columns: auto 1fr; align-items: center; }
161
+ input:where(:not([type]), [type="text"], [type="number"], [type="password"], [type="search"]), select, textarea {
162
+ height: var(--ctl-md); padding: 0 var(--sp-2); border: var(--bw) solid var(--line-strong); border-radius: var(--r-sm);
163
+ background: var(--surface); color: var(--ink); font: inherit; min-width: 0; }
164
+ textarea { height: auto; padding: var(--sp-2); resize: vertical; }
165
+ select:hover:where(:not(:focus-visible)), textarea:hover:where(:not(:focus-visible)) { border-color: var(--ink-3); }
166
+ input:where(:not([type]), [type="text"], [type="number"], [type="password"], [type="search"]):disabled, select:disabled, textarea:disabled { opacity: .6; }
167
+
168
+ dialog.dlg { width: min(480px, calc(100vw - 32px)); padding: 0; border: var(--bw) solid var(--line); border-radius: var(--r-xl);
169
+ background: var(--surface); color: var(--ink); box-shadow: var(--shadow-3); }
170
+ dialog.dlg::backdrop { background: var(--scrim); }
171
+ dialog.dlg form { margin: 0; }
172
+ .dlg-head { padding: var(--sp-5) var(--sp-5) 0; }
173
+ .dlg-head .h-title, dialog.dlg h2.h-title { margin: 0; font-size: var(--fs-lg); font-weight: var(--fw-strong); }
174
+ .dlg-body { display: grid; gap: var(--sp-3); padding: var(--sp-4) var(--sp-5); }
175
+ .dlg-body > p.sub { margin: 0; color: var(--ink-2); }
176
+ .dlg-foot { display: flex; justify-content: flex-end; align-items: center; gap: var(--sp-2); padding: 0 var(--sp-5) var(--sp-5); }
177
+ .dlg-foot .why { margin-right: auto; color: var(--ink-3); font-size: var(--fs-sm); }
178
+ .dlg-foot .why:empty, .dlg-foot .why[hidden] { display: none; }
179
+ .dlg-error:empty { display: none; }
180
+ .dlg-error:not(:empty) { margin: 0; color: var(--bad); font-size: var(--fs-sm); }
181
+ }
@@ -0,0 +1,262 @@
1
+ // The Monaco text pane: completion, hover, go to definition and problems from the editor core's providers (each
2
+ // pane's services: src/iso-editor/providers.ts given the domain's adapter). No language server: the same schema,
3
+ // reader and Document as the tests. This module is the Monaco adapter only.
4
+
5
+ // @ts-ignore Monaco's full editor entry, trimmed to the editor itself by the build (no d.ts for this path)
6
+ import * as monacoMain from 'monaco-editor/editor/editor.main.js';
7
+ // @ts-ignore registers the YAML grammar
8
+ import 'monaco-editor/languages/definitions/yaml/register.js';
9
+ import type { EditorModel } from '../model.ts';
10
+ import type { Problem } from '../validate.ts';
11
+ import type { Path } from '../path.ts';
12
+ import type { TextPane, TextSel, PaneOpts } from './pane.ts';
13
+
14
+ export type Monaco = typeof import('monaco-editor/editor/editor.api.js');
15
+ export const monaco = monacoMain as unknown as Monaco;
16
+ type IModel = import('monaco-editor/editor/editor.api.js').editor.ITextModel;
17
+ type Pos = import('monaco-editor/editor/editor.api.js').Position;
18
+ type Sel = import('monaco-editor/editor/editor.api.js').Selection;
19
+
20
+ // Monaco's editor thread (a Worker): a plain file beside the module that holds this code (the build says where:
21
+ // __SE_EDITOR_THREAD__), never a blob: URL. The pane turns off the features that need it (links, colour decorators,
22
+ // occurrence and unicode highlights, word-based suggestions), so it is normally never started; any thread made is
23
+ // ended at dispose.
24
+ declare const __SE_EDITOR_THREAD__: string | undefined;
25
+ const THREAD_URL = typeof __SE_EDITOR_THREAD__ === 'string' ? __SE_EDITOR_THREAD__ : 'editor.worker.js';
26
+ const threads = new Set<Worker>();
27
+ (self as unknown as { MonacoEnvironment: unknown }).MonacoEnvironment = {
28
+ getWorker: () => { const w = new Worker(new URL(THREAD_URL, import.meta.url)); threads.add(w); return w; },
29
+ };
30
+ /** P3: in the portable build Monaco's styles come with the text feature: the pane links them (the file beside Monaco,
31
+ * by a static relative URL), once per page. The standalone page has them in its own stylesheet. */
32
+ declare const __SE_MONACO_CSS__: string | undefined;
33
+ function monacoStyles() {
34
+ if (typeof __SE_MONACO_CSS__ !== 'string') return;
35
+ const href = new URL(__SE_MONACO_CSS__, import.meta.url).href;
36
+ if ([...document.querySelectorAll<HTMLLinkElement>('link[rel="stylesheet"]')].some(l => l.href === href)) return;
37
+ const l = document.createElement('link');
38
+ l.rel = 'stylesheet'; l.href = href; l.dataset.editor = 'monaco';
39
+ document.head.append(l);
40
+ }
41
+ /** threads Monaco has made and not been given back (for the tests) */
42
+ export const liveThreads = () => threads.size;
43
+
44
+ export type MonacoPane = TextPane & { editor: import('monaco-editor/editor/editor.api.js').editor.IStandaloneCodeEditor; model: IModel; monaco: Monaco; setReadOnly(ro: boolean): void; dispose(): void };
45
+
46
+ // ---------- the providers: registered once for YAML, answering for the pane that owns the model ----------
47
+ interface Owner { doc: EditorModel; opts: PaneOpts }
48
+ const owners = new Map<IModel, Owner>();
49
+ let providers: { dispose(): void }[] = [];
50
+ const rangeIn = (m: IModel, a: number, b: number) => { const s = m.getPositionAt(a), e = m.getPositionAt(b); return new monaco.Range(s.lineNumber, s.column, e.lineNumber, e.column); };
51
+ function registerProviders() {
52
+ if (providers.length) return;
53
+ const K = monaco.languages.CompletionItemKind;
54
+ providers = [monaco.languages.registerCompletionItemProvider('yaml', {
55
+ triggerCharacters: [' ', ':', '-', '[', ',', '{'],
56
+ provideCompletionItems(m: IModel, position: Pos) {
57
+ if (!owners.has(m)) return { suggestions: [] };
58
+ const s = owners.get(m)!.opts.services, c = s.completionAt(s.docFor(m.getValue()), m.getOffsetAt(position));
59
+ const r = rangeIn(m, c.from, m.getOffsetAt(position));
60
+ return {
61
+ suggestions: c.items.map((it, i) => ({
62
+ label: it.label,
63
+ kind: it.kind === 'key' ? K.Property : it.kind === 'ref' ? K.Reference : it.kind === 'snippet' ? K.Snippet : K.EnumMember,
64
+ insertText: it.insert,
65
+ insertTextRules: it.snippet ? monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet : undefined,
66
+ detail: it.detail, documentation: it.doc ? { value: it.doc } : undefined,
67
+ sortText: String(i).padStart(3, '0'), range: r,
68
+ })),
69
+ };
70
+ },
71
+ }), monaco.languages.registerHoverProvider('yaml', {
72
+ provideHover(m: IModel, position: Pos) {
73
+ const s = owners.get(m)?.opts.services, h = s ? s.hoverAt(s.docFor(m.getValue()), m.getOffsetAt(position)) : null;
74
+ return h ? { range: rangeIn(m, h.from, h.to), contents: h.parts.map(value => ({ value })) } : null;
75
+ },
76
+ }), monaco.languages.registerDefinitionProvider('yaml', {
77
+ provideDefinition(m: IModel, position: Pos) {
78
+ const s = owners.get(m)?.opts.services, d = s ? s.definitionAt(s.docFor(m.getValue()), m.getOffsetAt(position)) : null;
79
+ if (!d) return null;
80
+ if ('open' in d) { owners.get(m)!.opts.onOpen?.(d.open); return null; }
81
+ return [{ uri: m.uri, range: rangeIn(m, d.from, d.to) }];
82
+ },
83
+ })];
84
+ }
85
+
86
+ export function textPane(el: HTMLElement, doc: EditorModel, opts: PaneOpts): MonacoPane {
87
+ monacoStyles();
88
+ const editor = monaco.editor.create(el, {
89
+ // v0.4.1: the file as it is (a pane added after mount)
90
+ // two columns a level, never tabs (the default), whatever the file's own indentation (it is never detected)
91
+ value: doc.text, language: 'yaml', automaticLayout: true, minimap: { enabled: false }, fontSize: 12.5, tabSize: 2, detectIndentation: false,
92
+ scrollBeyondLastLine: false, renderWhitespace: 'none', fixedOverflowWidgets: true,
93
+ // nothing that needs Monaco's thread: no link detection, colour decorators, occurrence or unicode highlights
94
+ links: false, colorDecorators: false, occurrencesHighlight: 'off', selectionHighlight: false,
95
+ unicodeHighlight: { ambiguousCharacters: false, invisibleCharacters: false, nonBasicASCII: false },
96
+ quickSuggestions: { other: true, comments: false, strings: true }, suggestOnTriggerCharacters: true, wordBasedSuggestions: 'off',
97
+ suggest: { showWords: false, snippetsPreventQuickSuggestions: false }, hover: { delay: 250 },
98
+ fontFamily: 'ui-monospace, "SF Mono", Menlo, monospace',
99
+ });
100
+ const model = editor.getModel()!;
101
+ model.updateOptions({ tabSize: 2 });
102
+ const range = rangeIn;
103
+ owners.set(model, { doc, opts });
104
+ registerProviders();
105
+
106
+ // ---------- the binding: Monaco and the model, every edit crossing once ----------
107
+ // Typing: Monaco has the change already; the model takes it (coalesced, tagged 'monaco') and doesn't send it back.
108
+ // Everything else (tree, canvas, properties, undo, the other pane, a file): the model's steps go into Monaco with
109
+ // applyEdits, muted, so they don't come back as typing, and don't land on Monaco's own undo stack (never used).
110
+ const toSel = (ss: Sel[] | null): TextSel => (ss ?? []).map(s => ({ anchor: model.getOffsetAt(s.getSelectionStart()), head: model.getOffsetAt(s.getPosition()) }));
111
+ const fromSel = (ts: TextSel) => ts.map(s => { const a = model.getPositionAt(s.anchor), h = model.getPositionAt(s.head); return new monaco.Selection(a.lineNumber, a.column, h.lineNumber, h.column); });
112
+ let muted = false;
113
+ let lastSel: TextSel = [];
114
+ let resyncs = 0;
115
+ const resync = () => {
116
+ if (model.getValue() === doc.text) return;
117
+ resyncs++;
118
+ console.warn('editor: the Monaco pane and the model disagreed; the pane was put right');
119
+ const sel = editor.getSelections();
120
+ muted = true; model.setValue(doc.text); muted = false;
121
+ if (sel) editor.setSelections(sel);
122
+ };
123
+ model.onDidChangeContent(e => {
124
+ if (muted) return;
125
+ if (e.isUndoing || e.isRedoing) {
126
+ // Monaco's own undo (it shouldn't be reachable): put the text back, then undo the model's way
127
+ muted = true; model.setValue(doc.text); muted = false;
128
+ if (e.isUndoing) doc.undo(); else doc.redo();
129
+ return;
130
+ }
131
+ const step = e.changes.map(c => ({ start: c.rangeOffset, end: c.rangeOffset + c.rangeLength, text: c.text }));
132
+ const after = toSel(editor.getSelections());
133
+ doc.typed(step, { before: lastSel, after }, 'monaco');
134
+ lastSel = after;
135
+ resync();
136
+ });
137
+ editor.onDidChangeCursorSelection(e => {
138
+ if (muted) return;
139
+ lastSel = toSel(editor.getSelections());
140
+ if (editor.hasTextFocus()) doc.textSel = lastSel;
141
+ // a jump (a click, the arrows, a search) ends the typing being coalesced
142
+ if (e.reason === monaco.editor.CursorChangeReason.Explicit) doc.seal();
143
+ });
144
+ editor.onDidBlurEditorText(() => doc.seal());
145
+ doc.on(c => {
146
+ if (c.origin === 'text' && c.kind === 'do' && c.source === 'monaco') return;
147
+ muted = true;
148
+ try {
149
+ if (c.kind === 'load') model.setValue(doc.text);
150
+ else for (const step of c.steps) model.applyEdits([...step].sort((a, b) => a.start - b.start).map(x => ({ range: range(model, x.start, x.end), text: x.text })));
151
+ if (Array.isArray(c.textSel) && (c.kind === 'undo' || c.kind === 'redo')) editor.setSelections(fromSel(c.textSel as TextSel));
152
+ else if (c.kind !== 'load' && c.origin !== 'text' && c.steps[0]?.[0]) editor.revealLineInCenterIfOutsideViewport(model.getPositionAt(c.steps[0][0].start).lineNumber);
153
+ } finally { muted = false; }
154
+ lastSel = toSel(editor.getSelections());
155
+ resync();
156
+ });
157
+
158
+ // ---------- the selection: shown here when another view chose it; the caret's path chosen when it moves here ----------
159
+ let selDecos = editor.createDecorationsCollection([]);
160
+ const showSelection = (paths: Path[], move: boolean) => {
161
+ const ranges = paths.map(p => opts.services.rangeOfPath(doc.doc, p)).filter((r): r is [number, number] => !!r).map(([a, b]) => range(model, a, b));
162
+ selDecos.clear();
163
+ selDecos = editor.createDecorationsCollection(ranges.map(r => ({ range: r, options: { className: 'sel-range', isWholeLine: false, overviewRuler: { color: '#7f9cf580', position: monaco.editor.OverviewRulerLane.Center } } })));
164
+ if (move && ranges[0] && !editor.hasTextFocus()) {
165
+ muted = true;
166
+ editor.setPosition({ lineNumber: ranges[0].startLineNumber, column: ranges[0].startColumn });
167
+ muted = false;
168
+ editor.revealRangeInCenterIfOutsideViewport(ranges[0]);
169
+ }
170
+ };
171
+ doc.onSelect(c => { if (c.origin !== 'text' || !editor.hasTextFocus()) showSelection(c.paths, c.origin !== 'text'); else selDecos.clear(); });
172
+ let caretTimer = 0;
173
+ editor.onDidChangeCursorPosition(() => {
174
+ if (muted || !editor.hasTextFocus()) return;
175
+ clearTimeout(caretTimer);
176
+ caretTimer = window.setTimeout(() => {
177
+ const p = editor.getPosition();
178
+ if (!p) return;
179
+ const a = doc.doc.at(model.getOffsetAt(p));
180
+ doc.select(a.path.length ? [a.path] : [], 'text');
181
+ }, 120);
182
+ });
183
+
184
+ // one undo stack: ⌘Z / ⇧⌘Z / ⌘Y go to the model; ⌘S / ⇧⌘S to the page
185
+ editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyZ, () => doc.undo());
186
+ editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyMod.Shift | monaco.KeyCode.KeyZ, () => doc.redo());
187
+ editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyY, () => doc.redo());
188
+ editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyS, () => opts.onSave?.());
189
+ editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyMod.Shift | monaco.KeyCode.KeyS, () => opts.onSaveAs?.());
190
+
191
+ return {
192
+ id: 'monaco', el, editor, model, monaco, resyncs: () => resyncs, showSelection,
193
+ hasFocus: () => editor.hasTextFocus(), focus: () => editor.focus(),
194
+ goToOffset(off) { const p = model.getPositionAt(off); editor.setPosition(p); editor.revealPositionInCenter(p); editor.focus(); },
195
+ caret() { const p = editor.getPosition(); return p ? { line: p.lineNumber, col: p.column } : undefined; },
196
+ onCaret(fn) { editor.onDidChangeCursorPosition(fn); },
197
+ setTheme: dark => monaco.editor.setTheme(paneTheme(dark, el)),
198
+ setReadOnly: ro => editor.updateOptions({ readOnly: ro, readOnlyMessage: { value: 'Read-only' } }),
199
+ dispose() {
200
+ clearTimeout(caretTimer);
201
+ owners.delete(model);
202
+ editor.dispose();
203
+ model.dispose();
204
+ // the last pane gone: the providers and any thread go too
205
+ if (!owners.size) { for (const p of providers) p.dispose(); providers = []; for (const w of threads) w.terminate(); threads.clear(); }
206
+ },
207
+ goTo(path) {
208
+ showSelection([path], true);
209
+ const r = opts.services.rangeOfPath(doc.doc, path);
210
+ if (r) { const p = model.getPositionAt(r[0]); editor.setPosition(p); editor.revealPositionInCenter(p); }
211
+ editor.focus();
212
+ },
213
+ setProblems(ps: Problem[]) {
214
+ monaco.editor.setModelMarkers(model, 'problems', ps.map(p => ({
215
+ severity: p.severity === 'error' ? monaco.MarkerSeverity.Error : monaco.MarkerSeverity.Warning,
216
+ message: p.message + (p.hint ? `\n${p.hint}` : ''),
217
+ startLineNumber: p.startLine, startColumn: p.startCol, endLineNumber: p.endLine, endColumn: p.endCol,
218
+ source: p.file ?? undefined,
219
+ })));
220
+ },
221
+ pathAtCaret() {
222
+ const p = editor.getPosition();
223
+ return p ? doc.doc.at(model.getOffsetAt(p)).path : [];
224
+ },
225
+ };
226
+ }
227
+
228
+ /** Monaco themes made from the page's tokens (--surface, --ink…), as the page resolves them now (light or dark). */
229
+ export function paneTheme(dark: boolean, within: HTMLElement = document.body): string {
230
+ // read inside the editor's root: its color-scheme decides which side of each light-dark() token applies
231
+ const probe = document.createElement('div');
232
+ probe.style.display = 'none';
233
+ within.append(probe);
234
+ const tok = (v: string, prop: 'color' | 'backgroundColor' = 'color') => { probe.style[prop] = `var(${v})`; const c = getComputedStyle(probe)[prop]; return hex(c); };
235
+ const t = {
236
+ bg: tok('--surface', 'backgroundColor'), ink: tok('--ink'), ink2: tok('--ink-2'), ink3: tok('--ink-3'), line: tok('--line', 'backgroundColor'),
237
+ accent: tok('--accent'), tint: tok('--accent-tint', 'backgroundColor'), hover: tok('--surface-2', 'backgroundColor'),
238
+ };
239
+ probe.remove();
240
+ const name = dark ? 'iso-dark' : 'iso-light';
241
+ monaco.editor.defineTheme(name, {
242
+ base: dark ? 'vs-dark' : 'vs', inherit: true, rules: [],
243
+ colors: {
244
+ 'editor.background': t.bg, 'editor.foreground': t.ink, 'editorLineNumber.foreground': t.ink3, 'editorLineNumber.activeForeground': t.ink2,
245
+ 'editorCursor.foreground': t.accent, 'editor.selectionBackground': t.tint, 'editor.lineHighlightBackground': t.hover,
246
+ 'editorWidget.background': t.bg, 'editorWidget.border': t.line, 'editorSuggestWidget.background': t.bg, 'editorSuggestWidget.border': t.line,
247
+ 'editorSuggestWidget.selectedBackground': t.tint, 'editorHoverWidget.background': t.bg, 'editorHoverWidget.border': t.line, 'focusBorder': t.accent,
248
+ 'editorIndentGuide.background1': t.line,
249
+ // the selected row of a list (suggestions, hover actions): the ink on the accent tint
250
+ 'editorSuggestWidget.selectedForeground': t.ink, 'editorSuggestWidget.foreground': t.ink, 'editorSuggestWidget.highlightForeground': t.accent,
251
+ 'editorSuggestWidget.focusHighlightForeground': t.accent, 'list.activeSelectionForeground': t.ink, 'list.activeSelectionBackground': t.tint,
252
+ 'list.focusForeground': t.ink, 'list.focusBackground': t.tint, 'list.hoverBackground': t.hover, 'quickInputList.focusForeground': t.ink,
253
+ 'list.activeSelectionIconForeground': t.ink2, 'editorSuggestWidget.selectedIconForeground': t.ink2,
254
+ },
255
+ });
256
+ return name;
257
+ }
258
+ function hex(c: string): string {
259
+ const m = /rgba?\((\d+),\s*(\d+),\s*(\d+)/.exec(c);
260
+ if (!m) return '#000000';
261
+ return '#' + [m[1], m[2], m[3]].map(x => Number(x).toString(16).padStart(2, '0')).join('');
262
+ }