@johnoscott/isometric-engine 0.0.0-stage → 0.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (310) hide show
  1. package/EDITOR-GUIDE.md +355 -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 +269 -0
  8. package/assets/default-theme.yaml +99 -0
  9. package/assets/icons.svg +1 -0
  10. package/assets/marks.css +39 -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 +443 -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 +1403 -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 +149 -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 +511 -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 +147 -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 +477 -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 +1227 -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 +39 -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 +153 -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 +178 -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 +307 -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 +49 -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,210 @@
1
+ import { EditorDoc } from "./doc.js";
2
+ import { applyStep, invertStep } from "./splice.js";
3
+ const HISTORY_DEPTH = 500;
4
+ const COALESCE_MS = 1e3;
5
+ class EditorModel {
6
+ _text = "";
7
+ _doc;
8
+ _version = 0;
9
+ undoStack = [];
10
+ redoStack = [];
11
+ nextId = 1;
12
+ cleanId = 0;
13
+ listeners = /* @__PURE__ */ new Set();
14
+ selListeners = /* @__PURE__ */ new Set();
15
+ _good;
16
+ /** the selected paths (tree, canvas, properties) */
17
+ selection = [];
18
+ /** the text pane's selection, as it last reported it (opaque) */
19
+ textSel;
20
+ /** how many commands needed a fallback (re-serialising a collection): for the tests */
21
+ fallbacks = 0;
22
+ depth = HISTORY_DEPTH;
23
+ now = () => Date.now();
24
+ constructor(text = "") {
25
+ this._text = text;
26
+ }
27
+ get text() {
28
+ return this._text;
29
+ }
30
+ get version() {
31
+ return this._version;
32
+ }
33
+ get doc() {
34
+ return this._doc ??= new EditorDoc(this._text);
35
+ }
36
+ /** the document as last parsed without a YAML error: what the tree and canvas show while the text is broken */
37
+ get goodDoc() {
38
+ if (this.doc.ok) this._good = this.doc;
39
+ return this._good ?? this.doc;
40
+ }
41
+ /** Select paths (from a view). Every other view shows it. */
42
+ select(paths, origin) {
43
+ this.selection = paths;
44
+ for (const fn of this.selListeners) fn({ paths, origin });
45
+ }
46
+ onSelect(fn) {
47
+ this.selListeners.add(fn);
48
+ return () => this.selListeners.delete(fn);
49
+ }
50
+ on(fn) {
51
+ this.listeners.add(fn);
52
+ return () => this.listeners.delete(fn);
53
+ }
54
+ emit(c) {
55
+ for (const fn of this.listeners) fn(c);
56
+ }
57
+ /** A new file: the text, an empty history, clean. */
58
+ load(text, origin = "file") {
59
+ const old = this._text;
60
+ this.undoStack = [];
61
+ this.redoStack = [];
62
+ this.selection = [];
63
+ this._good = void 0;
64
+ this.set(text);
65
+ this.cleanId = 0;
66
+ this.emit({ kind: "load", origin, label: "Open", steps: [[{ start: 0, end: old.length, text }]], version: this._version });
67
+ }
68
+ set(text) {
69
+ this._text = text;
70
+ this._doc = void 0;
71
+ this._version++;
72
+ }
73
+ // ---------- doing ----------
74
+ /** Run a command: build it against the text, apply its steps, push it. Returns false if it changed nothing. */
75
+ apply(cmd, origin = "api") {
76
+ this.seal();
77
+ const splice = cmd.build(this._text);
78
+ if (!splice.steps.some((s) => s.length)) return false;
79
+ const before = { paths: this.selection, text: this.textSel };
80
+ const { inverse } = this.run(splice.steps);
81
+ const remap = cmd.remap ?? ((p) => p);
82
+ this.selection = cmd.select ?? this.selection.map(remap).filter((p) => p !== null);
83
+ if (splice.fallback) this.fallbacks++;
84
+ this.push({ id: this.nextId++, label: cmd.label, origin, steps: splice.steps, inverse, before, after: { paths: this.selection, text: this.textSel }, time: this.now(), fallback: !!splice.fallback, open: false });
85
+ this.emit({ kind: "do", origin, label: cmd.label, steps: splice.steps, version: this._version, remap: cmd.remap });
86
+ for (const fn of this.selListeners) fn({ paths: this.selection, origin });
87
+ return true;
88
+ }
89
+ /**
90
+ * Text the user typed (one change from the text pane: edits against the text before it). The view has already
91
+ * made the change; the model takes it, and coalesces typing into one command per word or pause.
92
+ */
93
+ typed(step, sel = {}, source) {
94
+ if (!step.length) return;
95
+ const time = this.now();
96
+ const top = this.undoStack[this.undoStack.length - 1];
97
+ const one = step.length === 1 ? step[0] : void 0;
98
+ const kind = one ? one.text && one.start === one.end ? "insert" : !one.text && one.end > one.start ? "delete" : void 0 : void 0;
99
+ let joins = !!(top && top.open && top.origin === "text" && top.source === source && this.redoStack.length === 0 && time - top.time < COALESCE_MS && one && kind && kind === top.typing);
100
+ if (joins && kind === "insert") {
101
+ const prevChar = this._text[one.start - 1] ?? "";
102
+ joins = one.start === top.caret && !one.text.includes("\n") && !(/[\w-]/.test(prevChar) && /^[^\w-]/.test(one.text));
103
+ }
104
+ if (joins && kind === "delete") joins = one.end === top.caret;
105
+ const { inverse } = this.run([step]);
106
+ if (joins) {
107
+ top.steps.push(step);
108
+ top.inverse.unshift(...inverse);
109
+ top.time = time;
110
+ top.after = { paths: this.selection, text: sel.after };
111
+ top.caret = kind === "insert" ? one.start + one.text.length : one.start;
112
+ } else {
113
+ this.seal();
114
+ this.push({
115
+ id: this.nextId++,
116
+ label: "Typing",
117
+ origin: "text",
118
+ steps: [step],
119
+ inverse,
120
+ before: { paths: this.selection, text: sel.before ?? this.textSel },
121
+ after: { paths: this.selection, text: sel.after },
122
+ time,
123
+ fallback: false,
124
+ open: !!kind,
125
+ caret: one ? kind === "insert" ? one.start + one.text.length : one.start : void 0,
126
+ typing: kind,
127
+ source
128
+ });
129
+ }
130
+ if (sel.after !== void 0) this.textSel = sel.after;
131
+ this.emit({ kind: "do", origin: "text", label: "Typing", steps: [step], version: this._version, source });
132
+ }
133
+ /** End the typing group being added to (a caret jump, a pause, leaving the text pane, a save). */
134
+ seal() {
135
+ const top = this.undoStack[this.undoStack.length - 1];
136
+ if (top) top.open = false;
137
+ }
138
+ run(steps) {
139
+ const inverse = [];
140
+ let t = this._text;
141
+ for (const s of steps) {
142
+ const next = applyStep(t, s);
143
+ inverse.unshift(invertStep(t, s));
144
+ t = next;
145
+ }
146
+ this.set(t);
147
+ return { inverse };
148
+ }
149
+ push(e) {
150
+ this.undoStack.push(e);
151
+ this.redoStack = [];
152
+ if (this.undoStack.length > this.depth) {
153
+ const dropped = this.undoStack.shift();
154
+ if (dropped.id === this.cleanId) this.cleanId = -1;
155
+ }
156
+ }
157
+ // ---------- undoing ----------
158
+ get canUndo() {
159
+ return this.undoStack.length > 0;
160
+ }
161
+ get canRedo() {
162
+ return this.redoStack.length > 0;
163
+ }
164
+ get undoLabel() {
165
+ return this.undoStack[this.undoStack.length - 1]?.label;
166
+ }
167
+ get redoLabel() {
168
+ return this.redoStack[this.redoStack.length - 1]?.label;
169
+ }
170
+ undo() {
171
+ this.seal();
172
+ const e = this.undoStack.pop();
173
+ if (!e) return false;
174
+ this.run(e.inverse);
175
+ this.redoStack.push(e);
176
+ this.selection = e.before.paths;
177
+ this.textSel = e.before.text;
178
+ this.emit({ kind: "undo", origin: "history", label: e.label, steps: e.inverse, version: this._version, textSel: e.before.text });
179
+ for (const fn of this.selListeners) fn({ paths: this.selection, origin: "history" });
180
+ return true;
181
+ }
182
+ redo() {
183
+ const e = this.redoStack.pop();
184
+ if (!e) return false;
185
+ this.run(e.steps);
186
+ this.undoStack.push(e);
187
+ this.selection = e.after.paths;
188
+ this.textSel = e.after.text;
189
+ this.emit({ kind: "redo", origin: "history", label: e.label, steps: e.steps, version: this._version, textSel: e.after.text });
190
+ for (const fn of this.selListeners) fn({ paths: this.selection, origin: "history" });
191
+ return true;
192
+ }
193
+ // ---------- saving ----------
194
+ /** The text was saved: this is the clean point. */
195
+ markClean() {
196
+ this.seal();
197
+ this.cleanId = this.undoStack[this.undoStack.length - 1]?.id ?? 0;
198
+ }
199
+ get dirty() {
200
+ return (this.undoStack[this.undoStack.length - 1]?.id ?? 0) !== this.cleanId;
201
+ }
202
+ /** the labels on the stack, oldest first (for tests and a history list) */
203
+ get history() {
204
+ return this.undoStack.map((e) => e.label);
205
+ }
206
+ }
207
+ export {
208
+ EditorModel,
209
+ HISTORY_DEPTH
210
+ };
@@ -0,0 +1,111 @@
1
+ import { isMap, isSeq, isScalar, isPair } from "yaml";
2
+ import { toPointer } from "./path.js";
3
+ const keyOf = (p) => isScalar(p.key) ? String(p.key.value) : String(p.key);
4
+ function outline(d, a, role = "main", tags) {
5
+ const text = d.text;
6
+ const data = d.data ?? {};
7
+ const scalarText = (n) => {
8
+ if (!n) return "";
9
+ const r = n.range;
10
+ if (r && r[1] > r[0]) {
11
+ const t = text.slice(r[0], r[1]).replace(/\s+$/, "");
12
+ if (/^[|>]/.test(t)) return (String(n.value ?? "").split("\n")[0] ?? "") + " \u2026";
13
+ return t;
14
+ }
15
+ return isScalar(n) ? String(n.value ?? "") : "";
16
+ };
17
+ const node = (n, path, label, kind, section) => {
18
+ const id = toPointer(path);
19
+ const ext = typeof path[path.length - 1] === "string" && String(path[path.length - 1]).startsWith("x-");
20
+ if (isMap(n)) {
21
+ return { id, path, kind, label, shape: "map", section, ext, children: n.items.map((p) => node(p.value, [...path, keyOf(p)], keyOf(p), "key")) };
22
+ }
23
+ if (isSeq(n)) {
24
+ return {
25
+ id,
26
+ path,
27
+ kind,
28
+ label,
29
+ shape: "list",
30
+ section,
31
+ ext,
32
+ value: n.items.length ? void 0 : "[]",
33
+ children: n.items.map((x, i) => node(x, [...path, i], isScalar(x) ? scalarText(x) : `${i + 1}`, "item"))
34
+ };
35
+ }
36
+ const out = { id, path, kind, label, shape: "scalar", value: scalarText(n), section, ext, children: [] };
37
+ if (kind === "item") {
38
+ out.label = out.value ?? "";
39
+ delete out.value;
40
+ }
41
+ return out;
42
+ };
43
+ const root = d.doc.contents;
44
+ const pairs = isMap(root) ? root.items : [];
45
+ const get = (k) => pairs.find((p) => keyOf(p) === k);
46
+ const children = [];
47
+ const used = /* @__PURE__ */ new Set();
48
+ for (const k of a.outline.first) {
49
+ const p = get(k);
50
+ if (p) {
51
+ children.push(node(p.value, [k], k, "key"));
52
+ used.add(k);
53
+ }
54
+ }
55
+ const nested = /* @__PURE__ */ new Set();
56
+ if (role === "main") {
57
+ for (const name of a.outline.kinds) {
58
+ const g = a.kinds.find((k) => k.kind === name);
59
+ const path = g.section.map(String);
60
+ const top = get(path[0]);
61
+ if (path.length === 1) used.add(path[0]);
62
+ else nested.add(path[0]);
63
+ let mapNode = top?.value;
64
+ if (path.length > 1) mapNode = isMap(mapNode) ? mapNode.items.find((p) => keyOf(p) === path[1])?.value : void 0;
65
+ const group = { id: toPointer(path), path, kind: "group", label: g.group, section: g.kind, shape: isMap(mapNode) ? "map" : "missing", children: [] };
66
+ if (isMap(mapNode)) {
67
+ for (const p of mapNode.items) {
68
+ const name2 = keyOf(p);
69
+ if (name2.startsWith("x-")) {
70
+ group.children.push(node(p.value, [...path, name2], name2, "key"));
71
+ continue;
72
+ }
73
+ const r = node(p.value, [...path, name2], name2, "resource", g.kind);
74
+ const tag = tags?.get(name2) ?? a.outline.tag?.(g.kind, name2, getIn(data, [...path, name2]), data);
75
+ if (tag !== void 0) r.lifetime = tag;
76
+ group.children.push(r);
77
+ }
78
+ }
79
+ children.push(group);
80
+ }
81
+ for (const top of nested) {
82
+ const holder = get(top);
83
+ const inner = new Set(a.kinds.filter((k) => String(k.section[0]) === top).map((k) => String(k.section[1])));
84
+ if (holder && isMap(holder.value)) {
85
+ used.add(top);
86
+ for (const p of holder.value.items) if (!inner.has(keyOf(p))) children.push(node(p.value, [top, keyOf(p)], `${top}.${keyOf(p)}`, "key"));
87
+ } else if (holder) used.add(top);
88
+ }
89
+ }
90
+ for (const { key: k, label, when } of a.outline.groups) {
91
+ const p = get(k);
92
+ used.add(k);
93
+ if (p) children.push({ ...node(p.value, [k], label, "group"), kind: "group" });
94
+ else if (role !== "other" && (!when || when(data))) children.push({ id: "/" + k, path: [k], kind: "group", label, shape: "missing", children: [] });
95
+ }
96
+ for (const p of pairs) {
97
+ const k = keyOf(p);
98
+ if (!used.has(k) && isPair(p)) children.push(node(p.value, [k], k, "key"));
99
+ }
100
+ return { id: "", path: [], kind: "root", label: a.outline.rootLabel(data, role), shape: "map", children };
101
+ }
102
+ const getIn = (o, p) => p.reduce((x, k) => x && typeof x === "object" ? x[k] : void 0, o);
103
+ function flatten(n, out = []) {
104
+ out.push(n);
105
+ for (const c of n.children) flatten(c, out);
106
+ return out;
107
+ }
108
+ export {
109
+ flatten,
110
+ outline
111
+ };
@@ -0,0 +1,6 @@
1
+ {
2
+ "//": "iso-editor (L3): only the Monaco pane and the Monaco bundle's entry have side effects (they set Monaco up when they load); bundles drop the modules they do not use. LAYERS.md S6, S7.",
3
+ "type": "module",
4
+ "private": true,
5
+ "sideEffects": ["./ui/text.ts", "./ui/monaco-entry.ts"]
6
+ }
@@ -0,0 +1,19 @@
1
+ const esc = (s) => String(s).replace(/~/g, "~0").replace(/\//g, "~1");
2
+ const toPointer = (p) => p.map((s) => "/" + esc(s)).join("");
3
+ function fromPointer(ptr) {
4
+ if (!ptr) return [];
5
+ return ptr.split("/").slice(1).map((s) => {
6
+ const u = s.replace(/~1/g, "/").replace(/~0/g, "~");
7
+ return /^\d+$/.test(u) ? Number(u) : u;
8
+ });
9
+ }
10
+ const parentOf = (p) => p.length ? p.slice(0, -1) : void 0;
11
+ const isPrefix = (a, b) => a.length <= b.length && a.every((s, i) => String(s) === String(b[i]));
12
+ const samePath = (a, b) => a.length === b.length && isPrefix(a, b);
13
+ export {
14
+ fromPointer,
15
+ isPrefix,
16
+ parentOf,
17
+ samePath,
18
+ toPointer
19
+ };
@@ -0,0 +1,96 @@
1
+ import { EditorDoc } from "./doc.js";
2
+ import { SchemaNav } from "./schema-nav.js";
3
+ import { complete } from "./complete.js";
4
+ import { toPointer } from "./path.js";
5
+ let last;
6
+ function docFor(text) {
7
+ if (last?.text !== text) last = new EditorDoc(text);
8
+ return last;
9
+ }
10
+ function providersFor(a) {
11
+ const navs = /* @__PURE__ */ new Map();
12
+ const navOf = (schema) => {
13
+ let n = navs.get(schema);
14
+ if (!n) navs.set(schema, n = new SchemaNav(schema));
15
+ return n;
16
+ };
17
+ const navFor = (text) => {
18
+ const role = a.role(text) === "base" ? "base" : "main";
19
+ return navOf(a.schema(role, text));
20
+ };
21
+ const sectionPath = (kind) => a.kinds.find((k) => k.kind === kind)?.section ?? [];
22
+ function completionAt(d, offset) {
23
+ const c = complete(d, offset, navFor(d.text), a);
24
+ const items = c.items.map((it, i) => ({ it, i })).sort((a2, b) => Number(!!b.it.preferred) - Number(!!a2.it.preferred) || a2.i - b.i).map((x) => x.it);
25
+ return { from: c.start, items };
26
+ }
27
+ function hoverAt(d, offset) {
28
+ const a2 = d.at(offset);
29
+ if (!a2.path.length || a2.where === "inside") return null;
30
+ const parts = [];
31
+ const doc = navFor(d.text).hover(a2.path);
32
+ if (doc) parts.push(`**${a2.path.join(".")}**
33
+
34
+ ${doc}`);
35
+ const ref = A.refs(d.data).find((r2) => r2.path === toPointer(a2.path));
36
+ if (ref?.name) {
37
+ const target = ref.slot.targets.map((s) => [...sectionPath(s), ref.name]).find((p) => d.rangeOf(p));
38
+ parts.push(target ? `\u2192 \`${target.join(".")}\` (line ${d.pos(d.rangeOf(target, "key")[0]).line}; \u2318-click to go there)` : `\u2192 no ${ref.slot.targets.join("/")} named \`${ref.name}\``);
39
+ }
40
+ if (!parts.length) return null;
41
+ const r = d.rangeOf(a2.path, a2.where === "key" ? "key" : "value") ?? [offset, offset];
42
+ return { from: r[0], to: r[1], parts };
43
+ }
44
+ function definitionAt(d, offset) {
45
+ const a2 = d.at(offset);
46
+ if (a2.path[0] === "extends" && a2.where !== "key") {
47
+ const v = d.nodeAt(a2.path);
48
+ if (typeof v?.value === "string") return { open: v.value };
49
+ }
50
+ const ref = A.refs(d.data).find((r) => r.path === toPointer(a2.path));
51
+ if (!ref?.name) return null;
52
+ for (const s of ref.slot.targets) {
53
+ const r = d.rangeOf([...sectionPath(s), ref.name], "key");
54
+ if (r) return { from: r[0], to: r[1] };
55
+ }
56
+ return null;
57
+ }
58
+ const A = a;
59
+ return { navFor, completionAt, hoverAt, definitionAt };
60
+ }
61
+ function rangeOfPath(d, p) {
62
+ return d.rangeOf(p, "pair") ?? d.rangeOf(p);
63
+ }
64
+ function problemRange(text, p) {
65
+ const starts = [0];
66
+ for (let i = text.indexOf("\n"); i >= 0; i = text.indexOf("\n", i + 1)) starts.push(i + 1);
67
+ const at = (line, col) => {
68
+ const l = Math.min(Math.max(line, 1), starts.length);
69
+ const end = l < starts.length ? starts[l] - 1 : text.length;
70
+ return Math.min(starts[l - 1] + Math.max(col, 1) - 1, end);
71
+ };
72
+ const a = at(p.startLine, p.startCol);
73
+ return [a, Math.max(a, at(p.endLine, p.endCol))];
74
+ }
75
+ function cmSnippet(monaco) {
76
+ return monaco.replace(/\$\{(\d+)\|([^|}]*)\|\}/g, (_m, n, opts) => `\${${n}:${opts.split(",")[0]}}`).replace(/\$\{0\}/g, "${}");
77
+ }
78
+ function mdRuns(md) {
79
+ return md.split(/\n{2,}/).map((par) => {
80
+ const runs = [];
81
+ for (const m of par.matchAll(/\*\*([^*]+)\*\*|`([^`]+)`|([^*`]+|[*`])/g)) {
82
+ if (m[1] !== void 0) runs.push({ kind: "bold", text: m[1] });
83
+ else if (m[2] !== void 0) runs.push({ kind: "code", text: m[2] });
84
+ else runs.push({ kind: "text", text: m[3] });
85
+ }
86
+ return runs;
87
+ });
88
+ }
89
+ export {
90
+ cmSnippet,
91
+ docFor,
92
+ mdRuns,
93
+ problemRange,
94
+ providersFor,
95
+ rangeOfPath
96
+ };
@@ -0,0 +1,117 @@
1
+ class SchemaNav {
2
+ root;
3
+ defs;
4
+ constructor(schema) {
5
+ this.root = schema;
6
+ this.defs = schema.$defs ?? {};
7
+ }
8
+ /** a schema with its $ref and anyOf/allOf branches spread out (each branch is a candidate) */
9
+ spread(s, seen = /* @__PURE__ */ new Set()) {
10
+ if (!s || typeof s !== "object" || seen.has(s)) return [];
11
+ seen.add(s);
12
+ const o = s;
13
+ const out = [o];
14
+ if (typeof o.$ref === "string" && o.$ref.startsWith("#/$defs/")) out.push(...this.spread(this.defs[o.$ref.slice(8)], seen));
15
+ for (const k of ["anyOf", "oneOf", "allOf"]) for (const b of o[k] ?? []) out.push(...this.spread(b, seen));
16
+ return out;
17
+ }
18
+ /** The candidate schemas at a path. A name in a section map matches additionalProperties; x-* keys match nothing useful. */
19
+ at(path) {
20
+ let cur = this.spread(this.root);
21
+ for (const seg of path) {
22
+ const next = [];
23
+ for (const s of cur) {
24
+ if (typeof seg === "number") {
25
+ if (s.items) next.push(...this.spread(s.items));
26
+ continue;
27
+ }
28
+ const props = s.properties ?? {};
29
+ if (props[seg] !== void 0) {
30
+ next.push(...this.spread(props[seg]));
31
+ continue;
32
+ }
33
+ const pp = Object.entries(s.patternProperties ?? {}).find(([re]) => new RegExp(re).test(seg));
34
+ if (pp) {
35
+ next.push(...this.spread(pp[1]));
36
+ continue;
37
+ }
38
+ if (s.additionalProperties && typeof s.additionalProperties === "object") next.push(...this.spread(s.additionalProperties));
39
+ }
40
+ cur = next;
41
+ if (!cur.length) break;
42
+ }
43
+ return cur;
44
+ }
45
+ /** The keys a map at this path may have (not counting x-*), given what the map holds now. */
46
+ keys(path, present = {}) {
47
+ const cands = this.at(path);
48
+ const forbidden = /* @__PURE__ */ new Set();
49
+ for (const s of cands) for (const [dep, sub] of Object.entries(s.dependentSchemas ?? {})) {
50
+ const banned = Object.entries(sub.properties ?? {}).filter(([, v]) => v === false).map(([k]) => k);
51
+ if (present[dep] !== void 0) banned.forEach((k) => forbidden.add(k));
52
+ else if (banned.some((k) => present[k] !== void 0)) forbidden.add(dep);
53
+ }
54
+ const out = /* @__PURE__ */ new Map();
55
+ for (const s of cands) for (const [k, v] of Object.entries(s.properties ?? {})) {
56
+ if (forbidden.has(k) || v === false) continue;
57
+ const prev = out.get(k);
58
+ const info = this.info(k, path, v);
59
+ if (!prev || !prev.doc && info.doc) out.set(k, info);
60
+ }
61
+ return [...out.values()];
62
+ }
63
+ info(name, path, s) {
64
+ const all = this.at([...path, name]).length ? this.at([...path, name]) : this.spread(s);
65
+ const doc = all.map((x) => x.markdownDescription ?? x.description).find(Boolean);
66
+ const types = new Set(all.flatMap((x) => Array.isArray(x.type) ? x.type : x.type ? [x.type] : []));
67
+ const hasProps = all.some((x) => x.properties || x.additionalProperties || x.patternProperties);
68
+ const shape = types.has("array") && !types.has("string") ? "list" : (types.has("object") || hasProps) && !types.has("string") && !all.some((x) => x.const !== void 0 || x.enum) ? "map" : "scalar";
69
+ return { name, doc, shape, enumValues: this.values([...path, name], all), examples: all.flatMap((x) => x.examples ?? []) };
70
+ }
71
+ /** The words a value at this path may be: enum values, consts, true/false. */
72
+ values(path, cands = this.at(path)) {
73
+ const out = /* @__PURE__ */ new Set();
74
+ for (const s of cands) {
75
+ for (const v of s.enum ?? []) out.add(String(v));
76
+ if (s.const !== void 0 && typeof s.const !== "object") out.add(String(s.const));
77
+ if (s.type === "boolean") {
78
+ out.add("true");
79
+ out.add("false");
80
+ }
81
+ }
82
+ return [...out];
83
+ }
84
+ /** Markdown for a path: the description of the key, plus allowed values. */
85
+ hover(path) {
86
+ const c = this.at(path);
87
+ const doc = c.map((x) => x.markdownDescription ?? x.description).find(Boolean);
88
+ if (!doc) return void 0;
89
+ const vals = this.values(path, c);
90
+ return doc + (vals.length && vals.length <= 12 ? `
91
+
92
+ One of: ${vals.map((v) => "`" + v + "`").join(", ")}` : "");
93
+ }
94
+ /** A value to start a new key with: the first allowed value, else an empty one of the right shape. */
95
+ defaultFor(path) {
96
+ const c = this.at(path);
97
+ const vals = this.values(path, c);
98
+ if (vals.length) return vals[0] === "true" || vals[0] === "false" ? false : vals[0];
99
+ const ex = c.flatMap((x) => x.examples ?? []).find((e) => typeof e === "string");
100
+ const types = new Set(c.flatMap((x) => Array.isArray(x.type) ? x.type : x.type ? [x.type] : []));
101
+ if (types.has("array")) return [];
102
+ if (types.has("object") || c.some((x) => x.properties || x.additionalProperties)) return {};
103
+ if (types.has("integer") || types.has("number")) return 1;
104
+ return ex ?? "";
105
+ }
106
+ /** The value types a path takes (for parsing what is typed into the tree). */
107
+ types(path) {
108
+ return new Set(this.at(path).flatMap((x) => Array.isArray(x.type) ? x.type : x.type ? [x.type] : []));
109
+ }
110
+ /** Is the path a map of names (a section of named things)? */
111
+ isNameMap(path) {
112
+ return this.at(path).some((s) => s.additionalProperties && typeof s.additionalProperties === "object" && !s.properties);
113
+ }
114
+ }
115
+ export {
116
+ SchemaNav
117
+ };