pict-section-form 1.1.0 → 1.1.2

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 (45) hide show
  1. package/docs/_cover.md +3 -0
  2. package/docs/_sidebar.md +5 -0
  3. package/docs/_version.json +3 -3
  4. package/docs/examples/README.md +3 -0
  5. package/docs/examples/change_tracking/change_tracking.js +9437 -9427
  6. package/docs/examples/diagram_form/README.md +116 -0
  7. package/docs/examples/diagram_form/diagram_form_example.min.js +42 -0
  8. package/docs/examples/diagram_form/excalidraw-iframe-host.html +25 -0
  9. package/docs/examples/diagram_form/excalidraw-wrapper.css +1 -0
  10. package/docs/examples/diagram_form/excalidraw-wrapper.min.js +3327 -0
  11. package/docs/examples/diagram_form/index.html +116 -0
  12. package/docs/examples/diagram_form/manifest.json +13 -0
  13. package/docs/examples/diagram_form/react-vendor.min.js +9 -0
  14. package/docs/examples/dynamic_analysis/dynamic_analysis_application.js +6549 -6550
  15. package/docs/examples/gradebook/gradebook_application.min.js +2 -2
  16. package/docs/examples/ndt_field_test/ndt_field_test.js +9437 -9427
  17. package/docs/examples/richtext_form/README.md +132 -0
  18. package/docs/examples/richtext_form/index.html +82 -0
  19. package/docs/examples/richtext_form/richtext_form_example.min.js +42 -0
  20. package/docs/examples/scope_mathematics/scope_mathematics.js +9437 -9427
  21. package/docs/examples/simple_table/simple_tabular_application.min.js +2 -2
  22. package/docs/examples/superhero_studio/README.md +199 -0
  23. package/docs/examples/superhero_studio/excalidraw-iframe-host.html +25 -0
  24. package/docs/examples/superhero_studio/excalidraw-wrapper.css +1 -0
  25. package/docs/examples/superhero_studio/excalidraw-wrapper.min.js +3327 -0
  26. package/docs/examples/superhero_studio/index.html +166 -0
  27. package/docs/examples/superhero_studio/manifest.json +13 -0
  28. package/docs/examples/superhero_studio/react-vendor.min.js +9 -0
  29. package/docs/examples/superhero_studio/superhero_studio_example.min.js +42 -0
  30. package/docs/index.html +2 -2
  31. package/docs/retold-catalog.json +45 -1
  32. package/docs/retold-keyword-index.json +11843 -7677
  33. package/example_applications/diagram_form/DiagramForm-Example-Application.js +145 -0
  34. package/example_applications/diagram_form/html/index.html +116 -0
  35. package/example_applications/diagram_form/package.json +29 -0
  36. package/example_applications/richtext_form/RichTextForm-Example-Application.js +176 -0
  37. package/example_applications/richtext_form/html/index.html +82 -0
  38. package/example_applications/richtext_form/package.json +28 -0
  39. package/example_applications/superhero_studio/SuperheroStudio-Example-Application.js +313 -0
  40. package/example_applications/superhero_studio/html/index.html +166 -0
  41. package/example_applications/superhero_studio/package.json +29 -0
  42. package/example_applications/superhero_studio/superheroes/Superheroes.js +386 -0
  43. package/package.json +3 -9
  44. package/source/providers/inputs/Pict-Provider-Input-Diagram.js +1 -31
  45. package/source/providers/inputs/Pict-Provider-Input-RichText.js +1 -32
@@ -0,0 +1,116 @@
1
+ # Diagram Form
2
+
3
+ <!-- docuserve:example-launch:start -->
4
+ > **[Launch the live app](examples/diagram%5Fform/index.html)** - runs in your browser, opens in a new tab.
5
+ <!-- docuserve:example-launch:end -->
6
+
7
+ **Diagram Form** is the smallest possible demonstration of the `Diagram`
8
+ InputType. A pict-section-form with exactly one field. Boots in view mode
9
+ (inline SVG), flips into Excalidraw on demand, and themeifies the SVG on
10
+ every save so the stored value resolves CSS variables on render.
11
+
12
+ The `Diagram` InputType + its provider class live in **pict-section-form**
13
+ (see [the Input Type doc](https://fable-retold.github.io/pict-section-form/#/page/input%5Fproviders/015-diagram)).
14
+ The provider lazy-requires this module on the first edit toggle — that's
15
+ why the Excalidraw vendor bundle isn't fetched at boot.
16
+
17
+ For the same InputType inside a real-feeling character-sheet form
18
+ alongside `Text` / `Number` / `Option` / `TextArea` / `RichText` fields,
19
+ see [Superhero Studio](../superhero%5Fstudio/README.md).
20
+
21
+ ## What it demonstrates
22
+
23
+ | Capability | Where you see it |
24
+ |------------|------------------|
25
+ | `Pict-Input-Diagram` provider registration | One `pict.addProvider(libPictSectionForm.DiagramInput.default_configuration, …)` call wires it into the form |
26
+ | Per-field runtime mode toggle | `provider.toggleMode('ArchDiagram', cb)` flips view ↔ edit |
27
+ | View-mode inline SVG | The provider writes the stored SVG verbatim into the slot; no Excalidraw bundle loaded |
28
+ | Edit-mode Excalidraw mount | First `setMode('edit')` lazy-loads the React vendor + wrapper, then mounts Excalidraw |
29
+ | Themeify-on-save | `Diagram.ThemeColors: true` runs the exported SVG through `themeifySVG()` before stamping into the form input |
30
+ | Live theme swap | Three swatches on the page hot-swap `--diagram-*` CSS variables; the view-mode SVG re-colors without a re-render |
31
+
32
+ ## Key files
33
+
34
+ - `DiagramForm-Example-Application.js` — the app. Registers the Diagram input provider, defines a one-field form manifest, seeds an inline demo SVG.
35
+ - `html/index.html` — page chrome: the toggle button, three theme swatches, and a `<style id="diagram-theme">` block that owns the live tokens.
36
+
37
+ ## The form descriptor
38
+
39
+ The shape is plain. The `Diagram` block carries the few provider-specific knobs:
40
+
41
+ ```javascript
42
+ 'ArchDiagram': {
43
+ Name: 'Architecture Diagram',
44
+ Hash: 'ArchDiagram',
45
+ DataType: 'String',
46
+ PictForm:
47
+ {
48
+ Section: 'Diagram',
49
+ Row: 1,
50
+ Width: 12,
51
+ InputType: 'Diagram',
52
+ Diagram:
53
+ {
54
+ ThemeColors: true, // pass the SVG through themeifySVG on save
55
+ Height: '480px', // applied to the slot in edit mode
56
+ EditorImplementation: 'react' // "react" or "iframe" — dispatches to PictView-Excalidraw-React/-Iframe
57
+ }
58
+ }
59
+ }
60
+ ```
61
+
62
+ The stored value is the **Excalidraw-exported SVG with embedded scene metadata**. View mode writes it into the slot directly. Edit mode reads the scene back out of the metadata via `vendor.loadFromBlob` and seeds Excalidraw with it — so round-tripping an existing diagram into edit mode never loses the original strokes.
63
+
64
+ ## Feature 1 — Themeify-on-save
65
+
66
+ When the user finishes drawing and the throttled `OnChange` fires:
67
+
68
+ 1. The provider calls `view.exportSvg({ exportEmbedScene: true, exportBackground: false })`.
69
+ 2. With `ThemeColors: true`, the result passes through `themeifySVG()` — every `stroke="#1B1F23"` becomes `stroke="var(--diagram-ink, #1B1F23)"`, and the metadata block is preserved byte-for-byte.
70
+ 3. The transformed SVG is stamped into the hidden form `<input>` and a `change` event fires so Informary picks it up.
71
+
72
+ The default palette tokens cover ink, paper, accent, highlight, deemphasis, link. Colors outside that palette stay raw (the regex anchors on `stroke=`/`fill=` followed by exactly one of the palette hex values).
73
+
74
+ ## Feature 2 — Live theme swap
75
+
76
+ The page's `<style id="diagram-theme">` block defines the tokens:
77
+
78
+ ```css
79
+ :root {
80
+ --diagram-ink: #1B1F23;
81
+ --diagram-paper: #FDFCF7;
82
+ --diagram-accent: #E66C2C;
83
+ --diagram-highlight: #FFD966;
84
+ --diagram-deemphasis: #A0A0A0;
85
+ --diagram-link: #2E7D74;
86
+ }
87
+ ```
88
+
89
+ Clicking a swatch calls `applyTheme(name)` which rewrites the `<style>` block. The view-mode SVG already carries `var(--diagram-*, fallback)` references, so the visible diagram re-colors with no app interaction. Open DevTools and confirm — no module code runs during the swap.
90
+
91
+ ## Feature 3 — Save round-trip preservation
92
+
93
+ Excalidraw's `exportToSvg({ exportEmbedScene: true })` writes a `<metadata>` block carrying a base64-encoded scene. `themeifySVG()` is metadata-safe: it carves the block out before its regex pass and reinserts it verbatim afterward. The stored SVG is a valid Excalidraw export — drop it into the [Embedded Excalidraw ↗](https://fable-retold.github.io/pict-section-excalidraw/#/page/examples/embedded%5Fexcalidraw/README) demo or [Full-Browser Excalidraw ↗](https://fable-retold.github.io/pict-section-excalidraw/#/page/examples/full%5Fbrowser%5Fexcalidraw/README) and it loads with the original elements intact.
94
+
95
+ ## Running the example
96
+
97
+ ```sh
98
+ cd modules/pict/pict-section-form/example_applications/diagram_form
99
+ npm install
100
+ npx quack build && npx quack copy
101
+ open dist/index.html
102
+ ```
103
+
104
+ The Excalidraw vendor bundle must already be present at `pict-section-excalidraw/vendor/excalidraw-built/`. Run `npm run build:vendor` from the module root once if it isn't.
105
+
106
+ ## Takeaways
107
+
108
+ 1. **One provider registration enables the InputType for every form on the Pict instance.** Templates are auto-injected; CSS is auto-registered; the form just sees `InputType: 'Diagram'`.
109
+ 2. **View mode is free.** Until a field flips to edit, the Excalidraw vendor isn't fetched. Read-mostly views never pay for the canvas runtime.
110
+ 3. **Theme is a property of the stored SVG, not of the app session.** Every saved diagram carries the same `var(...)` references with hex fallbacks; a host that swaps tokens later still gets correct rendering. A host with no theme provider gets the original notebook palette via the fallbacks.
111
+
112
+ ## Related documentation
113
+
114
+ - [Superhero Studio](../superhero%5Fstudio/README.md) — the same Diagram InputType inside a real character-sheet form.
115
+ - [Embedded Excalidraw ↗](https://fable-retold.github.io/pict-section-excalidraw/#/page/examples/embedded%5Fexcalidraw/README) — the underlying view, not yet wrapped as a form input.
116
+ - [Notebook Studio ↗](https://fable-retold.github.io/pict-section-excalidraw/#/page/examples/notebook%5Fstudio/README) — programmatic scene generation; pair with the Diagram input for pre-baked-then-editable diagrams.