@cocoar/vue-page-builder 2.19.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (202) hide show
  1. package/IDP_INTEGRATION.md +350 -0
  2. package/README.md +498 -169
  3. package/dist/BuilderElementCodeDialog-DXGNzleE.js +64 -0
  4. package/dist/BuilderExpressionDialog-yIfwYgXD.js +61 -0
  5. package/dist/BuilderLogicPanel-C9urz5Cd.js +68 -0
  6. package/dist/BuilderPageRootCodeDialog-CQsg_ozW.js +61 -0
  7. package/dist/CoarPageBuilder.vue.d.ts +71 -1
  8. package/dist/CoarPageBuilder.vue.d.ts.map +1 -1
  9. package/dist/CoarPageRenderer.vue.d.ts +36 -1
  10. package/dist/CoarPageRenderer.vue.d.ts.map +1 -1
  11. package/dist/PageNode.vue.d.ts +9 -1
  12. package/dist/PageNode.vue.d.ts.map +1 -1
  13. package/dist/VisualMarkupInspector-CmAOc-CH.js +54 -0
  14. package/dist/_plugin-vue_export-helper-BTgDAbhb.js +8 -0
  15. package/dist/actionValues.d.ts +21 -0
  16. package/dist/actionValues.d.ts.map +1 -0
  17. package/dist/assets/pageScriptRuntime.worker-Cll8Lm_I.js +25 -0
  18. package/dist/builder/BuilderCanvas.vue.d.ts +31 -1
  19. package/dist/builder/BuilderCanvas.vue.d.ts.map +1 -1
  20. package/dist/builder/BuilderCanvasNode.vue.d.ts.map +1 -1
  21. package/dist/builder/BuilderCompositionsPanel.vue.d.ts +3 -0
  22. package/dist/builder/BuilderCompositionsPanel.vue.d.ts.map +1 -0
  23. package/dist/builder/BuilderElementCodeDialog.vue.d.ts +14 -0
  24. package/dist/builder/BuilderElementCodeDialog.vue.d.ts.map +1 -0
  25. package/dist/builder/BuilderExpressionDialog.vue.d.ts +11 -0
  26. package/dist/builder/BuilderExpressionDialog.vue.d.ts.map +1 -0
  27. package/dist/builder/BuilderFxButton.vue.d.ts +28 -0
  28. package/dist/builder/BuilderFxButton.vue.d.ts.map +1 -0
  29. package/dist/builder/BuilderLogicPanel.vue.d.ts +3 -0
  30. package/dist/builder/BuilderLogicPanel.vue.d.ts.map +1 -0
  31. package/dist/builder/BuilderOutline.vue.d.ts.map +1 -1
  32. package/dist/builder/BuilderOutlineNode.vue.d.ts.map +1 -1
  33. package/dist/builder/BuilderPageRootCodeDialog.vue.d.ts +13 -0
  34. package/dist/builder/BuilderPageRootCodeDialog.vue.d.ts.map +1 -0
  35. package/dist/builder/BuilderPalette.vue.d.ts +3 -0
  36. package/dist/builder/BuilderPalette.vue.d.ts.map +1 -0
  37. package/dist/builder/BuilderPropsPanel.vue.d.ts.map +1 -1
  38. package/dist/builder/BuilderTranslationsPanel.vue.d.ts +6 -0
  39. package/dist/builder/BuilderTranslationsPanel.vue.d.ts.map +1 -0
  40. package/dist/builder/boxSides.d.ts +30 -0
  41. package/dist/builder/boxSides.d.ts.map +1 -0
  42. package/dist/builder/builderContext.d.ts +46 -4
  43. package/dist/builder/builderContext.d.ts.map +1 -1
  44. package/dist/builder/expressionAuthoring.d.ts +7 -0
  45. package/dist/builder/expressionAuthoring.d.ts.map +1 -0
  46. package/dist/builder/nodeDefaults.d.ts +10 -5
  47. package/dist/builder/nodeDefaults.d.ts.map +1 -1
  48. package/dist/builder/pageCodeAuthoring.d.ts +11 -0
  49. package/dist/builder/pageCodeAuthoring.d.ts.map +1 -0
  50. package/dist/builder/props/ActionPropsEditor.vue.d.ts +9 -0
  51. package/dist/builder/props/ActionPropsEditor.vue.d.ts.map +1 -0
  52. package/dist/builder/props/BuilderViewportControl.vue.d.ts +23 -0
  53. package/dist/builder/props/BuilderViewportControl.vue.d.ts.map +1 -0
  54. package/dist/builder/props/BuilderZoomControl.vue.d.ts +24 -0
  55. package/dist/builder/props/BuilderZoomControl.vue.d.ts.map +1 -0
  56. package/dist/builder/props/CompoundLengthProperty.vue.d.ts +20 -0
  57. package/dist/builder/props/CompoundLengthProperty.vue.d.ts.map +1 -0
  58. package/dist/builder/props/StyleProps.vue.d.ts +1 -0
  59. package/dist/builder/props/StyleProps.vue.d.ts.map +1 -1
  60. package/dist/builder/schemaMigrateV1.d.ts +7 -0
  61. package/dist/builder/schemaMigrateV1.d.ts.map +1 -1
  62. package/dist/builder/schemaNormalize.d.ts.map +1 -1
  63. package/dist/builder/{useSchemaValidation.d.ts → useAuthoringFindings.d.ts} +8 -8
  64. package/dist/builder/useAuthoringFindings.d.ts.map +1 -0
  65. package/dist/builder/useBuilderDnd.d.ts +8 -1
  66. package/dist/builder/useBuilderDnd.d.ts.map +1 -1
  67. package/dist/builder/useCanvasZoom.d.ts +50 -0
  68. package/dist/builder/useCanvasZoom.d.ts.map +1 -0
  69. package/dist/builder/usePageBuilder.d.ts +2 -0
  70. package/dist/builder/usePageBuilder.d.ts.map +1 -1
  71. package/dist/builder/usePageCompositions.d.ts +71 -0
  72. package/dist/builder/usePageCompositions.d.ts.map +1 -0
  73. package/dist/builderContext-B3rX2dxZ.js +4 -0
  74. package/dist/compositions.d.ts +79 -0
  75. package/dist/compositions.d.ts.map +1 -0
  76. package/dist/conditions.d.ts +8 -0
  77. package/dist/conditions.d.ts.map +1 -0
  78. package/dist/context.d.ts +17 -3
  79. package/dist/context.d.ts.map +1 -1
  80. package/dist/documentValidation.d.ts +12 -0
  81. package/dist/documentValidation.d.ts.map +1 -0
  82. package/dist/elements/builtins.d.ts.map +1 -1
  83. package/dist/elements/button/ButtonInspector.vue.d.ts.map +1 -1
  84. package/dist/elements/button/ButtonRenderer.vue.d.ts.map +1 -1
  85. package/dist/elements/button/index.d.ts +2 -2
  86. package/dist/elements/button/index.d.ts.map +1 -1
  87. package/dist/elements/card/CardInspector.vue.d.ts.map +1 -1
  88. package/dist/elements/card/index.d.ts.map +1 -1
  89. package/dist/elements/checkbox/CheckboxDefaultInput.vue.d.ts.map +1 -1
  90. package/dist/elements/checkbox/CheckboxInspector.vue.d.ts.map +1 -1
  91. package/dist/elements/checkbox/CheckboxRenderer.vue.d.ts.map +1 -1
  92. package/dist/elements/checkbox/index.d.ts.map +1 -1
  93. package/dist/elements/date-input/DateInputDefaultInput.vue.d.ts.map +1 -1
  94. package/dist/elements/date-input/DateInputInspector.vue.d.ts.map +1 -1
  95. package/dist/elements/date-input/index.d.ts.map +1 -1
  96. package/dist/elements/datetime-input/DateTimeInputDefaultInput.vue.d.ts.map +1 -1
  97. package/dist/elements/datetime-input/DateTimeInputInspector.vue.d.ts.map +1 -1
  98. package/dist/elements/datetime-input/index.d.ts.map +1 -1
  99. package/dist/elements/feedback/FeedbackInspector.vue.d.ts +8 -0
  100. package/dist/elements/feedback/FeedbackInspector.vue.d.ts.map +1 -0
  101. package/dist/elements/feedback/FeedbackPreview.vue.d.ts +7 -0
  102. package/dist/elements/feedback/FeedbackPreview.vue.d.ts.map +1 -0
  103. package/dist/elements/{stack/StackInspector.vue.d.ts → feedback/FeedbackRenderer.vue.d.ts} +3 -4
  104. package/dist/elements/feedback/FeedbackRenderer.vue.d.ts.map +1 -0
  105. package/dist/elements/feedback/index.d.ts +6 -0
  106. package/dist/elements/feedback/index.d.ts.map +1 -0
  107. package/dist/elements/heading/HeadingInspector.vue.d.ts.map +1 -1
  108. package/dist/elements/heading/index.d.ts.map +1 -1
  109. package/dist/elements/image/ImageInspector.vue.d.ts.map +1 -1
  110. package/dist/elements/image/index.d.ts.map +1 -1
  111. package/dist/elements/link/LinkInspector.vue.d.ts +1 -1
  112. package/dist/elements/link/LinkInspector.vue.d.ts.map +1 -1
  113. package/dist/elements/link/index.d.ts +1 -2
  114. package/dist/elements/link/index.d.ts.map +1 -1
  115. package/dist/elements/multi-select/MultiSelectDefaultInput.vue.d.ts.map +1 -1
  116. package/dist/elements/multi-select/MultiSelectInspector.vue.d.ts.map +1 -1
  117. package/dist/elements/multi-select/index.d.ts.map +1 -1
  118. package/dist/elements/note/NoteInspector.vue.d.ts.map +1 -1
  119. package/dist/elements/number-input/NumberInputDefaultInput.vue.d.ts.map +1 -1
  120. package/dist/elements/number-input/NumberInputInspector.vue.d.ts.map +1 -1
  121. package/dist/elements/number-input/index.d.ts.map +1 -1
  122. package/dist/elements/otp-input/OtpInputInspector.vue.d.ts.map +1 -1
  123. package/dist/elements/otp-input/index.d.ts.map +1 -1
  124. package/dist/elements/paragraph/index.d.ts.map +1 -1
  125. package/dist/elements/password-input/PasswordInputInspector.vue.d.ts.map +1 -1
  126. package/dist/elements/password-input/index.d.ts.map +1 -1
  127. package/dist/elements/previewUtils.d.ts.map +1 -1
  128. package/dist/elements/radio-group/RadioGroupDefaultInput.vue.d.ts.map +1 -1
  129. package/dist/elements/radio-group/RadioGroupInspector.vue.d.ts.map +1 -1
  130. package/dist/elements/radio-group/index.d.ts.map +1 -1
  131. package/dist/elements/registry.d.ts +265 -2
  132. package/dist/elements/registry.d.ts.map +1 -1
  133. package/dist/elements/repeat/RepeatInspector.vue.d.ts +8 -0
  134. package/dist/elements/repeat/RepeatInspector.vue.d.ts.map +1 -0
  135. package/dist/elements/repeat/RepeatRenderer.vue.d.ts +29 -0
  136. package/dist/elements/repeat/RepeatRenderer.vue.d.ts.map +1 -0
  137. package/dist/elements/repeat/index.d.ts +10 -0
  138. package/dist/elements/repeat/index.d.ts.map +1 -0
  139. package/dist/elements/section/SectionInspector.vue.d.ts.map +1 -1
  140. package/dist/elements/section/index.d.ts.map +1 -1
  141. package/dist/elements/select/SelectDefaultInput.vue.d.ts.map +1 -1
  142. package/dist/elements/select/SelectInspector.vue.d.ts.map +1 -1
  143. package/dist/elements/select/index.d.ts.map +1 -1
  144. package/dist/elements/spacer/SpacerInspector.vue.d.ts.map +1 -1
  145. package/dist/elements/stack/StackRenderer.vue.d.ts.map +1 -1
  146. package/dist/elements/stack/index.d.ts.map +1 -1
  147. package/dist/elements/switch/SwitchDefaultInput.vue.d.ts.map +1 -1
  148. package/dist/elements/switch/SwitchInspector.vue.d.ts.map +1 -1
  149. package/dist/elements/switch/index.d.ts.map +1 -1
  150. package/dist/elements/text-input/TextInputInspector.vue.d.ts.map +1 -1
  151. package/dist/elements/text-input/index.d.ts.map +1 -1
  152. package/dist/elements/usePageElement.d.ts +6 -2
  153. package/dist/elements/usePageElement.d.ts.map +1 -1
  154. package/dist/elements/visual-markup/VisualMarkupInspector.vue.d.ts +10 -0
  155. package/dist/elements/visual-markup/VisualMarkupInspector.vue.d.ts.map +1 -0
  156. package/dist/elements/visual-markup/VisualMarkupPreview.vue.d.ts +7 -0
  157. package/dist/elements/visual-markup/VisualMarkupPreview.vue.d.ts.map +1 -0
  158. package/dist/elements/visual-markup/VisualMarkupRenderer.vue.d.ts +7 -0
  159. package/dist/elements/visual-markup/VisualMarkupRenderer.vue.d.ts.map +1 -0
  160. package/dist/elements/visual-markup/index.d.ts +6 -0
  161. package/dist/elements/visual-markup/index.d.ts.map +1 -0
  162. package/dist/elements/visual-markup/visualDocument.d.ts +13 -0
  163. package/dist/elements/visual-markup/visualDocument.d.ts.map +1 -0
  164. package/dist/expressionAuthoring-7iAyadA3.js +74 -0
  165. package/dist/index.css +1 -1
  166. package/dist/index.d.ts +32 -2
  167. package/dist/index.d.ts.map +1 -1
  168. package/dist/index.js +8571 -3448
  169. package/dist/pageCode-echPQdna.js +455 -0
  170. package/dist/pageCode.d.ts +101 -0
  171. package/dist/pageCode.d.ts.map +1 -0
  172. package/dist/pageCodeAuthoring-C8grEAUf.js +123 -0
  173. package/dist/responsive.d.ts +7 -0
  174. package/dist/responsive.d.ts.map +1 -0
  175. package/dist/runtime/PageRuntimeHost.d.ts +57 -0
  176. package/dist/runtime/PageRuntimeHost.d.ts.map +1 -0
  177. package/dist/runtime/PageScriptRuntime.d.ts +62 -0
  178. package/dist/runtime/PageScriptRuntime.d.ts.map +1 -0
  179. package/dist/runtime/pageScriptRuntime.worker.d.ts +1 -0
  180. package/dist/runtime/pageScriptRuntime.worker.d.ts.map +1 -0
  181. package/dist/runtime/runtimeProtocol.d.ts +150 -0
  182. package/dist/runtime/runtimeProtocol.d.ts.map +1 -0
  183. package/dist/runtime/usePageCodeRuntime.d.ts +32 -0
  184. package/dist/runtime/usePageCodeRuntime.d.ts.map +1 -0
  185. package/dist/runtime-worker.js +240 -0
  186. package/dist/runtimeBindings.d.ts +32 -0
  187. package/dist/runtimeBindings.d.ts.map +1 -0
  188. package/dist/runtimeExpressions.d.ts +16 -0
  189. package/dist/runtimeExpressions.d.ts.map +1 -0
  190. package/dist/runtimeProtocol-Bg1C-O0c.js +36 -0
  191. package/dist/runtimeWorkerEntry.d.ts +2 -0
  192. package/dist/runtimeWorkerEntry.d.ts.map +1 -0
  193. package/dist/schema.d.ts +298 -31
  194. package/dist/schema.d.ts.map +1 -1
  195. package/dist/styleMapping.d.ts +7 -0
  196. package/dist/styleMapping.d.ts.map +1 -1
  197. package/dist/translations.d.ts +8 -0
  198. package/dist/translations.d.ts.map +1 -0
  199. package/dist/visualDocument-DKjWBfpW.js +139 -0
  200. package/package.json +24 -6
  201. package/dist/builder/useSchemaValidation.d.ts.map +0 -1
  202. package/dist/elements/stack/StackInspector.vue.d.ts.map +0 -1
package/README.md CHANGED
@@ -1,169 +1,498 @@
1
- # @cocoar/vue-page-builder
2
-
3
- A generic, headless visual page builder and renderer for Vue 3, built on the
4
- Cocoar Design System. Users drag UI primitives onto a canvas, configure them,
5
- and the result is a plain JSON schema (`PageNode`) that `<CoarPageRenderer>`
6
- turns back into live Cocoar components.
7
-
8
- Everything domain-specific — which actions a button may trigger, where images
9
- come from, which elements are permitted, which element types even exist is
10
- defined by the **consumer application** through a single `PageConfig`, not by
11
- the library. The renderer enforces `allowedElements` as a security boundary:
12
- disallowed nodes are skipped at render time, even in hand-written or tampered
13
- JSON.
14
-
15
- ## Install
16
-
17
- ```bash
18
- pnpm add @cocoar/vue-page-builder @cocoar/vue-ui
19
- ```
20
-
21
- `@cocoar/vue-ui` and `vue` are peer dependencies. Import the stylesheet once —
22
- it carries the builder chrome **and** the renderer's layout styles:
23
-
24
- ```ts
25
- import '@cocoar/vue-page-builder/styles';
26
- ```
27
-
28
- ## Usage
29
-
30
- ```vue
31
- <script setup lang="ts">
32
- import { ref } from 'vue';
33
- import {
34
- CoarPageBuilder,
35
- CoarPageRenderer,
36
- type PageNode,
37
- type PageConfig,
38
- } from '@cocoar/vue-page-builder';
39
-
40
- const schema = ref<PageNode>();
41
-
42
- const config: PageConfig = {
43
- allowedElements: ['stack', 'card', 'heading', 'paragraph', 'text-input', 'button'],
44
- availableActions: [{ id: 'auth:login', label: 'Sign in' }],
45
- };
46
- </script>
47
-
48
- <template>
49
- <!-- Visual editor (needs a bounded height) -->
50
- <CoarPageBuilder v-model="schema" :config="config" style="height: 700px" />
51
-
52
- <!-- Runtime renderer — same config = same boundary -->
53
- <CoarPageRenderer
54
- :schema="schema!"
55
- :config="config"
56
- :actions="{ 'auth:login': (values) => console.log(values) }"
57
- />
58
- </template>
59
- ```
60
-
61
- ## Schema (v2)
62
-
63
- The persisted document is a tree of one uniform node grammar: `type` is an
64
- open registry key (built-in or consumer), everything element-specific lives in
65
- the `props` bag, and the host vocabulary `id`, `style`, the value-model trio
66
- `name` / `defaultValue` / `validation`, and `children` for containers — stays
67
- at node level. The `page` root carries `schemaVersion: 2`.
68
-
69
- ```jsonc
70
- {
71
- "id": "3f6c…",
72
- "type": "page",
73
- "schemaVersion": 2,
74
- "style": { "gap": "16px", "padding": "24px" },
75
- "children": [
76
- { "id": "a1b2…", "type": "heading", "props": { "text": "Sign in", "level": 2 } },
77
- {
78
- "id": "c3d4…",
79
- "type": "text-input",
80
- "props": { "label": "Email", "inputType": "email" },
81
- "name": "email",
82
- "validation": { "required": true },
83
- "style": { "size": "fill" }
84
- },
85
- {
86
- "id": "e5f6…",
87
- "type": "button",
88
- "props": { "label": "Sign in", "action": "auth:login", "validates": true }
89
- }
90
- ]
91
- }
92
- ```
93
-
94
- Pre-v2 documents (flat element props, no `schemaVersion`) are migrated
95
- transparently on every ingest path; nodes with unknown/unregistered types are
96
- kept losslessly in the tree (flagged in the builder, skipped with a one-time
97
- warning at runtime).
98
-
99
- ## Custom elements
100
-
101
- The built-in elements are just pre-registered entries of an open **element
102
- registry** — a consumer can register its own element types on the exact same
103
- contract via `config.elements` (or app-wide via `PAGE_ELEMENTS_KEY`). One
104
- registration serves palette, canvas preview, props panel and the runtime
105
- renderer; the value model (defaults, `required`, validation, action payloads)
106
- comes from the host for free. Element renderers wire their field state through
107
- `usePageElement()`.
108
-
109
- ```ts
110
- import { definePageElement, type PageConfig } from '@cocoar/vue-page-builder';
111
- import RatingRenderer from './RatingRenderer.vue';
112
- import RatingInspector from './RatingInspector.vue';
113
-
114
- const ratingElement = definePageElement<{ label: string; max: number }>({
115
- renderer: RatingRenderer, // receives { node }; field wiring via usePageElement()
116
- value: { isEmpty: (v) => !v || Number(v) === 0 }, // participates in the form value model
117
- builder: {
118
- label: { key: 'app.pb.rating', fallback: 'Rating' },
119
- icon: 'star',
120
- defaults: () => ({ label: 'Rating', max: 5 }),
121
- inspector: RatingInspector, // receives { node, patch }
122
- },
123
- });
124
-
125
- const config: PageConfig = {
126
- elements: { 'acme-rating': ratingElement }, // vendor-prefixed key
127
- allowedElements: ['stack', 'heading', 'text-input', 'button', 'acme-rating'],
128
- };
129
- ```
130
-
131
- ## Field contract
132
-
133
- Pages are usually projections of a DTO — the field names and types are known
134
- up front. Declare them as `config.fields` and authors *pick* fields instead of
135
- inventing names: the props panel's field name becomes a select filtered to the
136
- value types each element can edit (`ElementValueSpec.types`; the rating above
137
- declares `types: ['number']` and shows up for number fields), the palette
138
- gains a draggable **Fields** group that drops pre-bound default elements, an
139
- **Element** select switches a bound field to another compatible
140
- representation, and the builder lint flags unknown names, incompatible
141
- bindings and missing required fields. Authoring-only: binding is plain
142
- `node.name`, so persisted schemas stay self-contained and render without the
143
- contract.
144
-
145
- ```ts
146
- const config: PageConfig = {
147
- fields: [
148
- { name: 'username', valueType: 'string', label: 'Username', required: true },
149
- { name: 'password', valueType: 'string', label: 'Password', required: true, defaultElement: 'password-input' },
150
- { name: 'rememberMe', valueType: 'boolean', label: 'Remember me' },
151
- { name: 'age', valueType: 'number', label: 'Age' },
152
- { name: 'dueUntil', valueType: 'date', label: 'Due until' },
153
- ],
154
- };
155
- ```
156
-
157
- ## Documentation
158
-
159
- Full docs schema reference, `PageConfig` contract, element registry guide,
160
- security model, and an IDP integration walkthrough at
161
- [docs.cocoar.dev/cocoar-ui-vue](https://docs.cocoar.dev/cocoar-ui-vue/components/page-builder/):
162
-
163
- - [Overview & `PageConfig`](https://docs.cocoar.dev/cocoar-ui-vue/components/page-builder/)
164
- - [`<CoarPageBuilder>`](https://docs.cocoar.dev/cocoar-ui-vue/components/page-builder/coar-page-builder)
165
- - [`<CoarPageRenderer>`](https://docs.cocoar.dev/cocoar-ui-vue/components/page-builder/coar-page-renderer)
166
-
167
- ## License
168
-
169
- Apache-2.0
1
+ # @cocoar/vue-page-builder
2
+
3
+ > **Preview.** This package is provisional. It shipped as GA in 2.17 by
4
+ > oversight; 3.0 puts it back under Preview until the authoring model settles.
5
+ > Public API, `PageConfig` and the document schema may still change in a minor
6
+ > release. Documents are safe — every schema change ships a migration that runs
7
+ > on ingest — so pin a version if you depend on the API.
8
+
9
+ A generic, headless visual page builder and renderer for Vue 3, built on the
10
+ Cocoar Design System. Users drag UI primitives onto a canvas, configure them,
11
+ and the result is a plain JSON schema (`PageNode`) that `<CoarPageRenderer>`
12
+ turns back into live Cocoar components.
13
+
14
+ Everything domain-specific — which actions a button may trigger, where images
15
+ come from, which elements are permitted, which element types even exist — is
16
+ defined by the **consumer application** through a single `PageConfig`, not by
17
+ the library. The renderer enforces `allowedElements` as a security boundary:
18
+ disallowed nodes are skipped at render time, even in hand-written or tampered
19
+ JSON.
20
+
21
+ ## Install
22
+
23
+ ```bash
24
+ pnpm add @cocoar/vue-page-builder @cocoar/vue-ui \
25
+ @cocoar/vue-localization @cocoar/vue-script-editor monaco-editor
26
+ ```
27
+
28
+ The UI, localization, ScriptEditor, Monaco and Vue packages are peers so the
29
+ host owns their single application-wide instances. Import the stylesheet once —
30
+ it carries the builder chrome **and** the renderer's layout styles:
31
+
32
+ ```ts
33
+ import '@cocoar/vue-page-builder/styles';
34
+ ```
35
+
36
+ The Builder uses Monaco in JavaScript and JSON mode. Register the TypeScript /
37
+ JavaScript and JSON workers before the first Builder mounts; the complete Vite
38
+ and SSR configurations are documented in
39
+ [IDP_INTEGRATION.md](./IDP_INTEGRATION.md#register-all-monaco-workers-used-by-the-builder).
40
+
41
+ ## Usage
42
+
43
+ ```vue
44
+ <script setup lang="ts">
45
+ import { ref } from 'vue';
46
+ import {
47
+ CoarPageBuilder,
48
+ CoarPageRenderer,
49
+ type PageNode,
50
+ type PageConfig,
51
+ } from '@cocoar/vue-page-builder';
52
+
53
+ const schema = ref<PageNode>();
54
+
55
+ const config: PageConfig = {
56
+ allowedElements: ['stack', 'card', 'heading', 'paragraph', 'text-input', 'button'],
57
+ availableActions: [{ id: 'auth:login', label: 'Sign in' }],
58
+ };
59
+ </script>
60
+
61
+ <template>
62
+ <!-- Visual editor (needs a bounded height) -->
63
+ <CoarPageBuilder v-model="schema" :config="config" style="height: 700px" />
64
+
65
+ <!-- Runtime renderer same config = same boundary -->
66
+ <CoarPageRenderer
67
+ :schema="schema!"
68
+ :config="config"
69
+ :actions="{ 'auth:login': (values) => console.log(values) }"
70
+ />
71
+ </template>
72
+ ```
73
+
74
+ ## Schema (v5)
75
+
76
+ The persisted document is a tree of one uniform node grammar: `type` is an
77
+ open registry key (built-in or consumer), everything element-specific lives in
78
+ the `props` bag, and the host vocabulary — `id`, `style`, the value-model trio
79
+ `name` / `defaultValue` / `validation`, and `children` for containers — stays
80
+ at node level. The `page` root carries `schemaVersion: 6`. Version 4 gives every
81
+ element a stable, page-wide `name`; value elements use that same name as their
82
+ form/DTO property and Element Code uses it as its authoring identity. Version 5
83
+ adds builder-only origin metadata for reusable, versioned compositions. Version
84
+ 6 renames the repeat's `props.source` to `props.contextPath`, so `source` means
85
+ one thing everywhere.
86
+
87
+ ```jsonc
88
+ {
89
+ "id": "3f6c…",
90
+ "type": "page",
91
+ "schemaVersion": 6,
92
+ "style": { "gap": "16px", "padding": "24px" },
93
+ "children": [
94
+ { "id": "a1b2…", "type": "heading", "props": { "text": "Sign in", "level": 2 } },
95
+ {
96
+ "id": "c3d4…",
97
+ "type": "text-input",
98
+ "props": { "label": "Email", "inputType": "email" },
99
+ "name": "email",
100
+ "validation": { "required": true },
101
+ "style": { "size": "fill" }
102
+ },
103
+ {
104
+ "id": "e5f6…",
105
+ "type": "button",
106
+ "props": { "label": "Sign in", "action": "auth:login", "validates": true }
107
+ }
108
+ ]
109
+ }
110
+ ```
111
+
112
+ Older documents are normalized transparently on every ingest path: pre-v2 flat
113
+ props move into the `props` bag, v3 runtime-composition documents keep their
114
+ meaning, and v4 deterministically adds missing element names. Unknown or
115
+ unregistered types stay losslessly in the tree (flagged in the builder, skipped
116
+ with a one-time warning at runtime).
117
+
118
+ ## Reusable compositions
119
+
120
+ Any non-page subtree can be stored and reused: a brand panel, header, form
121
+ section, footer, product card or a consumer element. Compositions are generic;
122
+ there are no auth-specific categories or runtime components.
123
+
124
+ The host owns persistence by implementing `PageCompositionRepository`. It may
125
+ use an API, IndexedDB or another store, and every method may be sync or async:
126
+
127
+ ```ts
128
+ import type { PageCompositionRepository } from '@cocoar/vue-page-builder';
129
+
130
+ const compositionRepository: PageCompositionRepository = {
131
+ list: () => api.get('/page-compositions'),
132
+ get: (id, version) => api.get(`/page-compositions/${id}/${version ?? 'latest'}`),
133
+ create: (input) => api.post('/page-compositions', input),
134
+ publish: (input) => api.post(`/page-compositions/${input.id}/versions`, input),
135
+ };
136
+ ```
137
+
138
+ Pass it only to the Builder:
139
+
140
+ ```vue
141
+ <CoarPageBuilder
142
+ v-model="authoringDocument"
143
+ :config="config"
144
+ :composition-repository="compositionRepository"
145
+ composition-management="consume"
146
+ @open-composition="({ id, version }) => openCompositionEditor(id, version)"
147
+ />
148
+ ```
149
+
150
+ `composition-management="consume"` is intended for a host with separate
151
+ **Pages** and **Compositions** areas. Page editors can insert an exact pinned
152
+ version, update it or detach it, but cannot create or publish definitions. The
153
+ host edits a definition as a standalone element subtree (usually inside a
154
+ temporary Page root) and calls `create()` / `publish()` itself. The default
155
+ `inline` mode additionally exposes create/publish in the Builder tab and is
156
+ useful for compact tools or bootstrapping a definition from an existing page.
157
+
158
+ Every repository summary is also exposed in the normal element palette under
159
+ **Compositions**. Dragging one to a valid tree/canvas drop zone loads its
160
+ displayed `latestVersion`, materializes the definition and pins that exact
161
+ version. Selecting the linked instance root exposes its name, pinned-version
162
+ selector, update, detach and open controls in Properties. `open-composition`
163
+ is the host navigation seam: the Builder emits the exact pinned `{ id,
164
+ version }`, while the host decides where its independent definition editor
165
+ lives. The existing Compositions tab remains the overview for references,
166
+ updates and repository problems.
167
+
168
+ Instances are fully materialized normal node trees. This gives drafts an
169
+ offline-safe snapshot and lets the Builder preserve page-local node ids and
170
+ public names across updates. Nested compositions keep a small origin chain so
171
+ each linked level can be updated or detached independently. Deleting an instance
172
+ from one page never deletes the repository definition or instances on other pages.
173
+
174
+ Before persisting a runtime document, remove authoring links deterministically:
175
+
176
+ ```ts
177
+ import { compilePageCompositions } from '@cocoar/vue-page-builder';
178
+
179
+ const runtimeDocument = compilePageCompositions(authoringDocument.value);
180
+ ```
181
+
182
+ The compiled result has no repository ids, versions or source-node metadata and
183
+ requires no composition repository at runtime. Use
184
+ `validatePageCompositionReferences(authoringDocument, repository)` before
185
+ publication to report missing versions and nested cycles. The package also
186
+ exports `createInMemoryPageCompositionRepository()` for tests and local demos.
187
+
188
+ ## Action payloads
189
+
190
+ Every action-capable element uses the same optional `ActionProps` contract:
191
+
192
+ ```ts
193
+ interface ActionProps {
194
+ action?: string;
195
+ actionValues?: Record<string, unknown>;
196
+ actionValueField?: string;
197
+ actionValue?: unknown;
198
+ }
199
+ ```
200
+
201
+ `actionValues` contains JSON-safe defaults. Every individual entry can be
202
+ switched to **fx** or bound through `bindings["actionValues.<key>"]` to a host
203
+ context value, customer Page State, form field, named Repeat selection, current
204
+ Repeat item/index, or a sandbox expression. `actionValue` /
205
+ `actionValueField` remain as the backwards-compatible single-dynamic-value
206
+ shape. The handler receives one snapshot with deterministic precedence:
207
+ **form values < resolved `actionValues` < dynamic `actionValue`**. Explicit
208
+ action arguments therefore win key collisions with form fields.
209
+
210
+ ```jsonc
211
+ {
212
+ "props": {
213
+ "action": "auth:consent-allow",
214
+ "actionValues": { "approvedScopes": [] }
215
+ },
216
+ "bindings": {
217
+ "actionValues.approvedScopes": {
218
+ "source": "selection",
219
+ "path": "approvedScopes"
220
+ }
221
+ }
222
+ }
223
+ ```
224
+
225
+ The builder supplies this editor automatically to built-in buttons/links and
226
+ to consumer elements registered with `action: true`. A custom action renderer
227
+ should call `usePageElement().triggerElementAction(node.props)` so it follows
228
+ the identical merge, validation and async-action path.
229
+
230
+ ## Host themes
231
+
232
+ Runtime applications wrap the renderer in the generic `CoarThemeScope` from
233
+ `@cocoar/vue-ui`. For authoring, pass the same theme as `previewTheme`; it is
234
+ applied only to the preview canvas, never to the builder chrome.
235
+
236
+ ## Decorative visual markup
237
+
238
+ The built-in `visual-markup` element is the deliberately narrow escape hatch
239
+ for branded, animated decoration that cannot reasonably be expressed through
240
+ individual PageBuilder primitives. It renders HTML, inline SVG and local CSS in
241
+ an opaque-origin iframe. It is **not** a general custom-code element:
242
+
243
+ - the iframe has an empty `sandbox`, `aria-hidden="true"`, `tabindex="-1"` and
244
+ `pointer-events: none`;
245
+ - JavaScript, forms, links, navigation, network access, parent-DOM access and
246
+ interactive controls are rejected or blocked by CSP;
247
+ - markup and CSS use strict allowlists and hard size limits;
248
+ - invalid visuals are hidden locally; siblings and the page form keep working;
249
+ - Builder Preview and Runtime use the same renderer and security policy.
250
+
251
+ Functional content must remain native PageBuilder elements. A visual node can
252
+ use local `@keyframes`, transforms, media queries, `prefers-reduced-motion`, CSS
253
+ custom properties and inline SVG. Its outer PageBuilder `style` controls its
254
+ size, including responsive `width`, `height`, `minHeight`, `maxHeight`,
255
+ `aspectRatio` and `size`.
256
+
257
+ Select the node to edit its HTML and CSS source with the dedicated Monaco
258
+ inspectors. These source editors remain available in code-driven authoring
259
+ mode; ordinary computed properties still use Element Code and Quick
260
+ Properties. Invalid source is reported on the node and in the inspector.
261
+
262
+ The host may inject only explicitly approved theme values and font files:
263
+
264
+ ```ts
265
+ import type { PageConfig } from '@cocoar/vue-page-builder';
266
+
267
+ const config: PageConfig = {
268
+ allowedElements: ['page', 'row', 'column', 'visual-markup', 'text-input', 'button'],
269
+ visualMarkup: {
270
+ themeVariables: {
271
+ '--coar-accent': '#10b981',
272
+ '--visual-surface': '#ffffff',
273
+ '--visual-text': '#16202e',
274
+ },
275
+ fonts: [{
276
+ id: 'brand-variable',
277
+ family: 'Brand Sans Variable',
278
+ source: approvedFontDataUrl, // data:font/...;base64 or a host-created blob URL
279
+ format: 'woff2',
280
+ weight: '100 900',
281
+ style: 'normal',
282
+ display: 'swap',
283
+ }],
284
+ },
285
+ };
286
+ ```
287
+
288
+ Font storage, tenant authorization and URL creation remain host
289
+ responsibilities. For deterministic opaque-iframe loading, a `data:font/...`
290
+ URL is the simplest option. Do not place secrets in theme values, fonts, markup
291
+ or CSS: they become part of the generated `srcdoc`.
292
+
293
+ ## Custom elements
294
+
295
+ The built-in elements are just pre-registered entries of an open **element
296
+ registry** — a consumer can register its own element types on the exact same
297
+ contract via `config.elementTypes` (or app-wide via `PAGE_ELEMENT_TYPES_KEY`). One
298
+ registration serves palette, canvas preview, props panel and the runtime
299
+ renderer; the value model (defaults, `required`, validation, action payloads)
300
+ comes from the host for free. Element renderers wire their field state through
301
+ `usePageElement()`.
302
+
303
+ ```ts
304
+ import { definePageElement, type PageConfig } from '@cocoar/vue-page-builder';
305
+ import RatingRenderer from './RatingRenderer.vue';
306
+ import RatingInspector from './RatingInspector.vue';
307
+
308
+ const ratingElement = definePageElement<{ label: string; max: number }>({
309
+ renderer: RatingRenderer, // receives { node }; field wiring via usePageElement()
310
+ value: { isEmpty: (v) => !v || Number(v) === 0 }, // participates in the form value model
311
+ builder: {
312
+ label: { key: 'app.pb.rating', fallback: 'Rating' },
313
+ icon: 'star',
314
+ defaults: () => ({ label: 'Rating', max: 5 }),
315
+ inspector: RatingInspector, // receives { node, patch }
316
+ },
317
+ });
318
+
319
+ const config: PageConfig = {
320
+ elements: { 'acme-rating': ratingElement }, // vendor-prefixed key
321
+ allowedElements: ['stack', 'heading', 'text-input', 'button', 'acme-rating'],
322
+ };
323
+ ```
324
+
325
+ ## Field contract
326
+
327
+ Every element has one page-wide unique `name`, which is its exact Page-Code
328
+ key (`elements.pageTitle`). For value elements, the same name is also the form
329
+ and DTO property (`elements.username` and `fields.username`); there is no
330
+ second field-name or identifier property.
331
+
332
+ Pages are usually projections of a DTO — the value-element names and types are
333
+ known up front. Declare them as `config.dataContract` and authors *pick* fields instead
334
+ of inventing names: the props panel's Name becomes a select filtered to the
335
+ value types each element can edit (`ElementValueSpec.types`; the rating above
336
+ declares `types: ['number']` and shows up for number fields), the palette
337
+ gains a draggable **Fields** group that drops pre-bound default elements, an
338
+ **Element** select switches a bound field to another compatible
339
+ representation, and the builder lint flags unknown names, incompatible
340
+ bindings and missing required fields. Authoring-only: binding is plain
341
+ `node.name`, so persisted schemas stay self-contained and render without the
342
+ contract.
343
+
344
+ ```ts
345
+ const config: PageConfig = {
346
+ fields: [
347
+ { name: 'username', valueType: 'string', label: 'Username', required: true },
348
+ { name: 'password', valueType: 'string', label: 'Password', required: true, defaultElement: 'password-input' },
349
+ { name: 'rememberMe', valueType: 'boolean', label: 'Remember me' },
350
+ { name: 'age', valueType: 'number', label: 'Age' },
351
+ { name: 'dueUntil', valueType: 'date', label: 'Due until' },
352
+ ],
353
+ };
354
+ ```
355
+
356
+ ## Page-owned translations
357
+
358
+ Human-readable element properties use stable translation keys instead of
359
+ embedding one object per language into every node. The root owns the editable
360
+ catalogue and Element Code keeps only a data-safe reference:
361
+
362
+ ```jsonc
363
+ {
364
+ "type": "page",
365
+ "translations": {
366
+ "de": { "page.submit.label": "Anmelden" },
367
+ "en": { "page.submit.label": "Sign in" }
368
+ }
369
+ }
370
+ ```
371
+
372
+ ```js
373
+ element.props.label = i18n.text('page.submit.label', undefined, 'Sign in');
374
+ ```
375
+
376
+ The Builder's **Translations** tab edits the catalogue, reports missing/unused
377
+ keys and shares its language with the preview. Localizability is explicit
378
+ element metadata (`valueKind: 'localized-text'`), so layout strings such as
379
+ `style.width` never accidentally get translation UI. Monaco completes the
380
+ keys present in the page document. At runtime page messages win, then the
381
+ host's `@cocoar/vue-localization` store is consulted, followed by the binding
382
+ fallback and finally the key itself. The legacy `LocalizedValue` shape remains
383
+ readable for existing documents, but new authoring uses translation bindings.
384
+
385
+ ## JavaScript property bindings
386
+
387
+ Bindable properties can retain a static fallback and opt into a pure
388
+ JavaScript expression. In the right-hand Properties panel, a compact `fx`
389
+ control in the property's label row switches modes without opening an editor
390
+ (struck through = static, accent colour = expression). Its explicit Edit action
391
+ opens the shared lazy Monaco dialog. Disabled expressions remain persisted with
392
+ `enabled: false`, so switching modes never loses authored code. The optional
393
+ Logic overview opens that same dialog and edits the same record:
394
+
395
+ ```ts
396
+ const submit = {
397
+ id: 'submit',
398
+ type: 'button',
399
+ props: { label: 'Sign in', disabled: false },
400
+ bindings: {
401
+ disabled: {
402
+ source: 'expression',
403
+ expression: '!fields.username?.trim() || !fields.password',
404
+ },
405
+ },
406
+ };
407
+ ```
408
+
409
+ The builder never evaluates this source. A host-owned sandbox session extracts
410
+ definitions with `collectPageRuntimeExpressions()`, evaluates them, and passes
411
+ the data-only result map to `CoarPageRenderer.expressionValues` (or
412
+ `CoarPageBuilder.previewExpressionValues`). Static props remain active during
413
+ startup and after runtime failures. Monaco is lazy-loaded in JavaScript mode;
414
+ host field/context contracts provide its IntelliSense declarations.
415
+
416
+ ## Browser Page Runtime
417
+
418
+ The package contains the SES Worker runtime used by Page State, constrained Page
419
+ Root Code and per-element code.
420
+ Create the host once in the consumer application. It is a capability catalogue,
421
+ not shared page state; every `usePageCodeRuntime()` call owns an isolated Worker
422
+ session and disposes it with the Vue component.
423
+
424
+ ```ts
425
+ import {
426
+ definePageRuntimeHost,
427
+ withRuntimeEndowmentContext,
428
+ } from '@cocoar/vue-page-builder';
429
+
430
+ export const pageRuntimeHost = definePageRuntimeHost({
431
+ endowments: {
432
+ api: {
433
+ loadOptions: withRuntimeEndowmentContext(
434
+ ({ signal, tenantId }, source: unknown) =>
435
+ applicationApi.loadOptions(String(source), { tenantId, signal }),
436
+ ),
437
+ },
438
+ },
439
+ grants: ({ pageId, definition }) =>
440
+ pageId.startsWith('auth:') && definition.id.startsWith('element-action:')
441
+ ? ['api']
442
+ : [],
443
+ });
444
+ ```
445
+
446
+ ```ts
447
+ const runtime = usePageCodeRuntime({
448
+ pageId,
449
+ tenantId,
450
+ schema,
451
+ context,
452
+ viewport,
453
+ runtimeHost: pageRuntimeHost,
454
+ });
455
+ ```
456
+
457
+ Pass `runtime.pageCodeValues` and `runtime.onRuntimeChange` to the renderer and
458
+ route unknown action ids through `runtime.runPageAction`. If no host is passed,
459
+ the package uses a no-capability host: there is no ambient `fetch`, `window`, DOM
460
+ or application API inside tenant code.
461
+
462
+ The consuming Vite build emits the SES runtime as a same-origin
463
+ `pageScriptRuntime.worker-<hash>.js` module asset. Keep the document CSP free of
464
+ `unsafe-eval`; see `IDP_INTEGRATION.md` for the Worker-response CSP requirement.
465
+ For Vite development, exclude only the dedicated runtime entry from dependency
466
+ pre-bundling:
467
+
468
+ ```ts
469
+ optimizeDeps: { exclude: ['@cocoar/vue-page-builder/runtime-worker'] }
470
+ ```
471
+
472
+ `CoarPageBuilder` owns its embedded preview runtime. The host supplies its
473
+ inputs — `previewContext`, `previewInitialValues`, `previewLocale` — and the
474
+ Builder evaluates Page State, Page Root Code and Element Code in one isolated
475
+ session against exactly those. Pass `previewRuntimeHost` only when preview actions
476
+ need the application's explicitly granted capabilities.
477
+
478
+ The package ships no auth-specific configuration or documents. An IDP owns its
479
+ own `PageConfig` and starting documents for `login`, `password-forgot`, `logout`
480
+ and `consent`; every element, repeater, feedback zone and runtime API stays
481
+ generic.
482
+
483
+ See [IDP_INTEGRATION.md](./IDP_INTEGRATION.md) for the complete draft/publish,
484
+ host-action and security contract.
485
+
486
+ ## Documentation
487
+
488
+ Full docs — schema reference, `PageConfig` contract, element registry guide,
489
+ security model, and an IDP integration walkthrough — at
490
+ [docs.cocoar.dev/cocoar-ui-vue](https://docs.cocoar.dev/cocoar-ui-vue/components/page-builder/):
491
+
492
+ - [Overview & `PageConfig`](https://docs.cocoar.dev/cocoar-ui-vue/components/page-builder/)
493
+ - [`<CoarPageBuilder>`](https://docs.cocoar.dev/cocoar-ui-vue/components/page-builder/coar-page-builder)
494
+ - [`<CoarPageRenderer>`](https://docs.cocoar.dev/cocoar-ui-vue/components/page-builder/coar-page-renderer)
495
+
496
+ ## License
497
+
498
+ Apache-2.0