@nubisco/cms-vue 1.0.0 → 1.1.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.
@@ -0,0 +1,2 @@
1
+ .cms-text--editing[data-v-57962fd1]{outline:1px dashed color-mix(in srgb, var(--nb-c-primary,#5856a9) 55%, transparent);outline-offset:3px;cursor:text;border-radius:4px}.cms-text--editing[data-v-57962fd1]:hover{background:color-mix(in srgb, var(--nb-c-primary,#5856a9) 6%, transparent)}.cms-text--editing[data-v-57962fd1]:focus{outline:2px solid var(--nb-c-primary,#5856a9);background:color-mix(in srgb, var(--nb-c-primary,#5856a9) 9%, transparent)}
2
+ /*$vite$:1*/
package/dist/index.d.ts CHANGED
@@ -1,4 +1,345 @@
1
- export * from './contract';
2
- export * from './evaluate';
3
- export * from './graph';
4
- export * from './resolve';
1
+ import { ComponentOptionsMixin } from 'vue';
2
+ import { ComponentProvideOptions } from 'vue';
3
+ import { DefineComponent } from 'vue';
4
+ import { InjectionKey } from 'vue';
5
+ import { PublicProps } from 'vue';
6
+
7
+ declare type __VLS_Props = {
8
+ block: BlockInstance;
9
+ field: string;
10
+ };
11
+
12
+ export declare type BlockCategory = 'content' | 'media' | 'form' | 'layout';
13
+
14
+ /**
15
+ * A block type definition, registered once. The editor catalog, the inspector
16
+ * fields, validation, and serialization all derive from this, mirroring how the
17
+ * NubiscoUI Blueprint system derives everything from a NodeDefinition.
18
+ *
19
+ * Coded blocks map `type` to a real component through a per-framework registry
20
+ * that lives in the renderer package, not in this contract.
21
+ */
22
+ export declare interface BlockDefinition {
23
+ type: string;
24
+ label: string;
25
+ kind: BlockKind;
26
+ category?: BlockCategory;
27
+ icon?: string;
28
+ fields: Record<string, FieldSchema>;
29
+ variations?: BlockVariation[];
30
+ slots?: Record<string, SlotSchema>;
31
+ }
32
+
33
+ /** A block as it appears in a content document. */
34
+ export declare interface BlockInstance {
35
+ /** Stable id: survives reorder, used for deep links and in-place edit targeting. */
36
+ id: string;
37
+ type: string;
38
+ variation?: string;
39
+ fields: Record<string, FieldValue>;
40
+ /** Visibility logic. Absent means always visible. */
41
+ when?: Condition;
42
+ /** Nested blocks for composed blocks with slots. */
43
+ slots?: Record<string, BlockInstance[]>;
44
+ }
45
+
46
+ export declare type BlockKind =
47
+ /** Fields only, assembled in the CMS. No app code required. */
48
+ 'composed'
49
+ /** Backed by an app component (anything with behavior, e.g. a form). */
50
+ | 'coded';
51
+
52
+ export declare interface BlockVariation {
53
+ id: string;
54
+ label: string;
55
+ /** Field values this variation presets (a footer subscribe vs a hero one). */
56
+ presets?: Record<string, FieldValue>;
57
+ }
58
+
59
+ export declare interface BlueprintCard {
60
+ id: string;
61
+ x: number;
62
+ y: number;
63
+ width: number;
64
+ height: number;
65
+ paint: {
66
+ title: string;
67
+ color: string;
68
+ category: string;
69
+ ports: NodePort[];
70
+ };
71
+ }
72
+
73
+ export declare const CMS_CONTEXT: InjectionKey<CmsContext>;
74
+
75
+ /**
76
+ * Render context provided by CmsZone and injected by field primitives. It
77
+ * carries the string table (for { $t } refs), whether edit mode is on, and the
78
+ * write-back hook. In edit mode the primitives decorate the real DOM; off, they
79
+ * render plain text. This is where the in-context editor hangs off the render.
80
+ */
81
+ export declare interface CmsContext {
82
+ messages: Record<string, string>;
83
+ editing: boolean;
84
+ setText: (block: BlockInstance, field: string, current: FieldValue | undefined, next: string) => void;
85
+ }
86
+
87
+ export declare const CmsText: DefineComponent<__VLS_Props, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, ComponentProvideOptions, false, {
88
+ el: HTMLSpanElement;
89
+ }, any>;
90
+
91
+ export declare type Condition = {
92
+ kind: 'always';
93
+ } | {
94
+ kind: 'simple';
95
+ /** A registered LogicInputDefinition id. */
96
+ input: string;
97
+ /** Input parameters, e.g. { flag: 'stagewright' } for featureFlag. */
98
+ params?: Record<string, unknown>;
99
+ /** Comparison for enum/number/date inputs. Boolean inputs need none. */
100
+ op?: Op;
101
+ value?: unknown;
102
+ } | {
103
+ kind: 'all';
104
+ of: Condition[];
105
+ } | {
106
+ kind: 'any';
107
+ of: Condition[];
108
+ } | {
109
+ kind: 'not';
110
+ of: Condition;
111
+ }
112
+ /** Reference to a serialized Blueprint graph stored alongside the content. */
113
+ | {
114
+ kind: 'graph';
115
+ graphId: string;
116
+ };
117
+
118
+ /**
119
+ * The initial catalog. Extend by appending a definition (and, for the visual
120
+ * editor, a matching Blueprint NodeDefinition). `campaignSource` is the worked
121
+ * example of a future input: append one entry with resolveAt: 'request'.
122
+ */
123
+ export declare const CORE_LOGIC_INPUTS: LogicInputDefinition[];
124
+
125
+ /**
126
+ * Evaluates a Condition tree to a visibility boolean. `graphs` supplies the
127
+ * logic graphs referenced by { kind: 'graph' } conditions (stored on the page
128
+ * document); a graph condition with no matching graph defaults to visible.
129
+ */
130
+ export declare function evaluate(condition: Condition | undefined, env: LogicEnv, graphs?: Record<string, LogicGraph>): boolean;
131
+
132
+ /** Evaluates the graph to the Visible sink's value, plus each node's output. */
133
+ export declare function evaluateGraph(graph: LogicGraph, env: LogicEnv): GraphResult;
134
+
135
+ /** A field's schema: what a Block declares it accepts. */
136
+ export declare interface FieldSchema {
137
+ type: FieldType;
138
+ /** Editor-facing label. */
139
+ label: string;
140
+ help?: string;
141
+ required?: boolean;
142
+ /**
143
+ * Whether the value is per-locale. Text/richtext default to true and are
144
+ * stored by reference (see TRef) so Verba owns the translations. Media,
145
+ * numbers, and booleans default to false.
146
+ */
147
+ localized?: boolean;
148
+ /** Allowed values for `select`. */
149
+ options?: string[];
150
+ default?: unknown;
151
+ /** Max length for text, or max value for number. */
152
+ max?: number;
153
+ }
154
+
155
+ /**
156
+ * Content contract: the framework-agnostic shape of Nubisco CMS content.
157
+ *
158
+ * This is the crown jewel of the system. The CMS edits documents of this shape,
159
+ * and any renderer (Vue first, others later) is just a function from these types
160
+ * to a rendered page. Nothing here mentions Vue on purpose.
161
+ *
162
+ * Vocabulary: Fields (primitives) compose into Blocks (placeable units), which
163
+ * are ordered inside Zones on a Page.
164
+ */
165
+ export declare type FieldType = 'text' | 'richtext' | 'number' | 'boolean' | 'image' | 'link' | 'color' | 'date' | 'select';
166
+
167
+ export declare type FieldValue = TRef | string | number | boolean | ImageValue | LinkValue;
168
+
169
+ export declare interface GraphConnection {
170
+ fromNode: string;
171
+ fromPort: string;
172
+ toNode: string;
173
+ toPort: string;
174
+ }
175
+
176
+ export declare interface GraphResult {
177
+ visible: boolean;
178
+ nodeOut: Record<string, boolean>;
179
+ }
180
+
181
+ export declare interface ImageValue {
182
+ src: string;
183
+ alt?: TRef;
184
+ /** Intrinsic size, when known, to avoid layout shift. */
185
+ w?: number;
186
+ h?: number;
187
+ }
188
+
189
+ /**
190
+ * Resolves one logic input to a boolean, given the author's params/op/value.
191
+ * The host provides one resolver per registered input id (featureFlag,
192
+ * environment, auth, region, ...). This is where build-time vs request-time
193
+ * resolution actually happens; the contract only declares which is which.
194
+ */
195
+ export declare type InputResolver = (params: Record<string, unknown> | undefined, op: Op | undefined, value: unknown) => boolean;
196
+
197
+ export declare function isImage(v: unknown): v is ImageValue;
198
+
199
+ export declare function isLink(v: unknown): v is LinkValue;
200
+
201
+ export declare function isTRef(v: unknown): v is TRef;
202
+
203
+ export declare interface LinkValue {
204
+ href: string;
205
+ label?: TRef;
206
+ external?: boolean;
207
+ }
208
+
209
+ export declare type LogicEnv = Record<string, InputResolver>;
210
+
211
+ export declare interface LogicGraph {
212
+ nodes: LogicNode[];
213
+ connections: GraphConnection[];
214
+ }
215
+
216
+ export declare interface LogicInputDefinition {
217
+ id: string;
218
+ label: string;
219
+ valueType: LogicValueType;
220
+ /** Parameters the author fills in, e.g. featureFlag needs a `flag`. */
221
+ params?: Record<string, FieldSchema>;
222
+ resolveAt: ResolveAt;
223
+ /** Allowed values for enum inputs (environment, region, locale). */
224
+ enumValues?: string[];
225
+ }
226
+
227
+ /**
228
+ * A logic input type, registered once. The value is resolved by a host-provided
229
+ * resolver keyed by `id`; this definition only declares the shape and where it
230
+ * can run, so the visual editor and the evaluator are fully data-driven.
231
+ */
232
+ export declare type LogicKind = 'featureFlag' | 'environment' | 'auth' | 'region' | 'and' | 'or' | 'not' | 'visible';
233
+
234
+ export declare interface LogicNode {
235
+ id: string;
236
+ kind: LogicKind;
237
+ x: number;
238
+ y: number;
239
+ /** Flag key / environment value / region code, for the input nodes. */
240
+ param?: string;
241
+ }
242
+
243
+ export declare type LogicValueType = 'boolean' | 'enum' | 'number' | 'date';
244
+
245
+ export declare const NODE_SPECS: Record<LogicKind, NodeSpec>;
246
+
247
+ /**
248
+ * App-side logic for the graph form of a Condition (the data shapes live in the
249
+ * contract). The node catalog, Blueprint card mapping, and evaluator are here.
250
+ * Inputs (feature flag, environment, ...) feed gates (AND/OR/NOT) that feed a
251
+ * single Visible sink; graphs are referenced from a condition as
252
+ * { kind: 'graph', graphId }.
253
+ */
254
+ declare interface NodePort {
255
+ id: string;
256
+ label: string;
257
+ type: 'input' | 'output';
258
+ }
259
+
260
+ declare interface NodeSpec {
261
+ label: string;
262
+ color: string;
263
+ category: string;
264
+ ports: NodePort[];
265
+ /** Which parameter this node carries, if any. */
266
+ param?: 'flag' | 'environment' | 'region';
267
+ }
268
+
269
+ /**
270
+ * Logic contract: visibility and variation conditions.
271
+ *
272
+ * A Condition gates whether a Block or Page renders. It is either a simple
273
+ * predicate, a boolean tree, or a reference to a NubiscoUI Blueprint graph for
274
+ * the genuinely compound cases. Most content uses a simple predicate; the graph
275
+ * is the escape hatch, not the default.
276
+ *
277
+ * Logic inputs are a registry. Adding a new input type (e.g. campaign source)
278
+ * later is one LogicInputDefinition plus one Blueprint NodeDefinition. Nothing
279
+ * in the engine or the content schema changes.
280
+ */
281
+ export declare type Op = 'is' | 'not' | 'in' | 'gte' | 'lte' | 'between';
282
+
283
+ export declare interface PageDocument {
284
+ route: string;
285
+ meta?: {
286
+ title?: TRef;
287
+ description?: TRef;
288
+ /** Page renders its own newsletter, so the footer one is suppressed. */
289
+ ownNewsletter?: boolean;
290
+ };
291
+ /** Named zones, usually just `main`. */
292
+ zones: Record<string, Zone>;
293
+ /** Whole-page gate, e.g. a product feature flag. */
294
+ when?: Condition;
295
+ /** Logic graphs referenced by block/page conditions via { kind: 'graph', graphId }. */
296
+ graphs?: Record<string, LogicGraph>;
297
+ }
298
+
299
+ /**
300
+ * Where a logic input can be evaluated. This is load-bearing for delivery:
301
+ * - `build` inputs (flag, environment, locale) let a gated block prerender.
302
+ * - `request` inputs (auth, region) force the block to be resolved at the edge
303
+ * (a Worker) or revealed client-side. It cannot be baked.
304
+ * A block whose condition mixes both is resolved at the most dynamic site.
305
+ */
306
+ export declare type ResolveAt = 'build' | 'request';
307
+
308
+ /** A named region inside a composed block that nests other blocks. */
309
+ export declare interface SlotSchema {
310
+ label: string;
311
+ /** Block types allowed in this slot. Omit to allow any. */
312
+ allow?: string[];
313
+ }
314
+
315
+ /**
316
+ * Resolves a field value to display text. String refs ({ $t }) resolve from the
317
+ * provided message table (Verba / locale JSON), falling back to the key so a
318
+ * missing translation is visible rather than blank.
319
+ */
320
+ export declare function text(value: FieldValue | undefined, messages: Record<string, string>): string;
321
+
322
+ /** Maps the logic graph to Blueprint card geometry + paint. */
323
+ export declare function toCards(graph: LogicGraph): BlueprintCard[];
324
+
325
+ /**
326
+ * A reference to an i18n key. Localized strings are never inlined into content;
327
+ * they resolve from Verba / the site's locale JSON at render time. This keeps
328
+ * Verba authoritative and the content documents small, and it matches how the
329
+ * existing sites already use vue-i18n keys.
330
+ */
331
+ export declare interface TRef {
332
+ $t: string;
333
+ }
334
+
335
+ /** Small helper for block components: resolve a field value to display text. */
336
+ export declare function useField(): {
337
+ t: (value: FieldValue | undefined) => string;
338
+ };
339
+
340
+ /** An ordered list of blocks. Array order is render order and reorder order. */
341
+ export declare interface Zone {
342
+ blocks: BlockInstance[];
343
+ }
344
+
345
+ export { }
package/dist/index.js CHANGED
@@ -1,4 +1,332 @@
1
- export * from './contract';
2
- export * from './evaluate';
3
- export * from './graph';
4
- export * from './resolve';
1
+ import { computed as e, createElementBlock as t, defineComponent as n, inject as r, openBlock as i, ref as a, toDisplayString as o, unref as s, withKeys as c, withModifiers as l } from "vue";
2
+ //#region src/contract/logic.ts
3
+ var u = [
4
+ {
5
+ id: "featureFlag",
6
+ label: "Feature flag",
7
+ valueType: "boolean",
8
+ params: { flag: {
9
+ type: "text",
10
+ label: "Flag key",
11
+ required: !0
12
+ } },
13
+ resolveAt: "build"
14
+ },
15
+ {
16
+ id: "environment",
17
+ label: "Environment",
18
+ valueType: "enum",
19
+ enumValues: ["staging", "production"],
20
+ resolveAt: "build"
21
+ },
22
+ {
23
+ id: "locale",
24
+ label: "Locale",
25
+ valueType: "enum",
26
+ enumValues: [
27
+ "en",
28
+ "pt",
29
+ "es",
30
+ "fr"
31
+ ],
32
+ resolveAt: "build"
33
+ },
34
+ {
35
+ id: "schedule",
36
+ label: "Schedule window",
37
+ valueType: "date",
38
+ params: {
39
+ from: {
40
+ type: "date",
41
+ label: "From"
42
+ },
43
+ to: {
44
+ type: "date",
45
+ label: "To"
46
+ }
47
+ },
48
+ resolveAt: "build"
49
+ },
50
+ {
51
+ id: "auth",
52
+ label: "Signed in",
53
+ valueType: "boolean",
54
+ resolveAt: "request"
55
+ },
56
+ {
57
+ id: "region",
58
+ label: "Region",
59
+ valueType: "enum",
60
+ enumValues: [
61
+ "EU",
62
+ "NA",
63
+ "SA",
64
+ "AS",
65
+ "AF",
66
+ "OC"
67
+ ],
68
+ resolveAt: "request"
69
+ }
70
+ ], d = {
71
+ featureFlag: {
72
+ label: "Feature flag",
73
+ color: "#6e6bd6",
74
+ category: "input",
75
+ ports: [{
76
+ id: "out",
77
+ label: "on",
78
+ type: "output"
79
+ }],
80
+ param: "flag"
81
+ },
82
+ environment: {
83
+ label: "Environment",
84
+ color: "#b9781e",
85
+ category: "input",
86
+ ports: [{
87
+ id: "out",
88
+ label: "is",
89
+ type: "output"
90
+ }],
91
+ param: "environment"
92
+ },
93
+ auth: {
94
+ label: "Signed in",
95
+ color: "#2c9560",
96
+ category: "input",
97
+ ports: [{
98
+ id: "out",
99
+ label: "yes",
100
+ type: "output"
101
+ }]
102
+ },
103
+ region: {
104
+ label: "Region",
105
+ color: "#3a86c8",
106
+ category: "input",
107
+ ports: [{
108
+ id: "out",
109
+ label: "in",
110
+ type: "output"
111
+ }],
112
+ param: "region"
113
+ },
114
+ and: {
115
+ label: "AND",
116
+ color: "#5a5a6a",
117
+ category: "gate",
118
+ ports: [
119
+ {
120
+ id: "a",
121
+ label: "a",
122
+ type: "input"
123
+ },
124
+ {
125
+ id: "b",
126
+ label: "b",
127
+ type: "input"
128
+ },
129
+ {
130
+ id: "out",
131
+ label: "out",
132
+ type: "output"
133
+ }
134
+ ]
135
+ },
136
+ or: {
137
+ label: "OR",
138
+ color: "#5a5a6a",
139
+ category: "gate",
140
+ ports: [
141
+ {
142
+ id: "a",
143
+ label: "a",
144
+ type: "input"
145
+ },
146
+ {
147
+ id: "b",
148
+ label: "b",
149
+ type: "input"
150
+ },
151
+ {
152
+ id: "out",
153
+ label: "out",
154
+ type: "output"
155
+ }
156
+ ]
157
+ },
158
+ not: {
159
+ label: "NOT",
160
+ color: "#5a5a6a",
161
+ category: "gate",
162
+ ports: [{
163
+ id: "in",
164
+ label: "in",
165
+ type: "input"
166
+ }, {
167
+ id: "out",
168
+ label: "out",
169
+ type: "output"
170
+ }]
171
+ },
172
+ visible: {
173
+ label: "Visible",
174
+ color: "#c0392b",
175
+ category: "output",
176
+ ports: [{
177
+ id: "in",
178
+ label: "show",
179
+ type: "input"
180
+ }]
181
+ }
182
+ };
183
+ function f(e) {
184
+ return e.nodes.map((e) => {
185
+ let t = d[e.kind], n = e.param ? `${t.label}: ${e.param}` : t.label;
186
+ return {
187
+ id: e.id,
188
+ x: e.x,
189
+ y: e.y,
190
+ width: 160,
191
+ height: 52 + t.ports.length * 8,
192
+ paint: {
193
+ title: n,
194
+ color: t.color,
195
+ category: t.category,
196
+ ports: t.ports
197
+ }
198
+ };
199
+ });
200
+ }
201
+ function p(e, t) {
202
+ let n = {}, r = (t, n) => e.connections.find((e) => e.toNode === t && e.toPort === n)?.fromNode, i = (e, t) => {
203
+ let n = r(e, t);
204
+ return n ? a(n) : !1;
205
+ };
206
+ function a(r) {
207
+ if (r in n) return n[r];
208
+ n[r] = !1;
209
+ let a = e.nodes.find((e) => e.id === r);
210
+ if (!a) return !1;
211
+ let o = !1;
212
+ switch (a.kind) {
213
+ case "featureFlag":
214
+ o = t.featureFlag?.({ flag: a.param ?? "" }, void 0, void 0) ?? !1;
215
+ break;
216
+ case "environment":
217
+ o = t.environment?.(void 0, "is", a.param ?? "staging") ?? !1;
218
+ break;
219
+ case "auth":
220
+ o = t.auth?.(void 0, void 0, void 0) ?? !1;
221
+ break;
222
+ case "region":
223
+ o = t.region?.(void 0, "in", [a.param ?? ""]) ?? !1;
224
+ break;
225
+ case "and":
226
+ o = i(r, "a") && i(r, "b");
227
+ break;
228
+ case "or":
229
+ o = i(r, "a") || i(r, "b");
230
+ break;
231
+ case "not":
232
+ o = !i(r, "in");
233
+ break;
234
+ case "visible": o = i(r, "in");
235
+ }
236
+ return n[r] = o, o;
237
+ }
238
+ let o = e.nodes.find((e) => e.kind === "visible"), s = {};
239
+ for (let t of e.nodes) s[t.id] = a(t.id);
240
+ return {
241
+ visible: o ? a(o.id) : !1,
242
+ nodeOut: s
243
+ };
244
+ }
245
+ //#endregion
246
+ //#region src/evaluate.ts
247
+ function m(e, t, n) {
248
+ if (!e || e.kind === "always") return !0;
249
+ switch (e.kind) {
250
+ case "simple": {
251
+ let n = t[e.input];
252
+ return n ? n(e.params, e.op, e.value) : !1;
253
+ }
254
+ case "all": return e.of.every((e) => m(e, t, n));
255
+ case "any": return e.of.some((e) => m(e, t, n));
256
+ case "not": return !m(e.of, t, n);
257
+ case "graph": {
258
+ let r = n?.[e.graphId];
259
+ return !r || p(r, t).visible;
260
+ }
261
+ }
262
+ }
263
+ //#endregion
264
+ //#region src/resolve.ts
265
+ function h(e) {
266
+ return typeof e == "object" && !!e && "$t" in e;
267
+ }
268
+ function g(e) {
269
+ return typeof e == "object" && !!e && "src" in e;
270
+ }
271
+ function _(e) {
272
+ return typeof e == "object" && !!e && "href" in e;
273
+ }
274
+ function v(e, t) {
275
+ return e == null ? "" : typeof e == "string" ? e : typeof e == "number" || typeof e == "boolean" ? String(e) : h(e) ? t[e.$t] ?? e.$t : "";
276
+ }
277
+ //#endregion
278
+ //#region src/context.ts
279
+ var y = Symbol("cms-context");
280
+ //#endregion
281
+ //#region src/useField.ts
282
+ function b() {
283
+ let e = r(y, {
284
+ messages: {},
285
+ editing: !1,
286
+ setText: () => {}
287
+ });
288
+ return { t: (t) => v(t, e.messages) };
289
+ }
290
+ //#endregion
291
+ //#region src/CmsText.vue?vue&type=script&setup=true&lang.ts
292
+ var x = [
293
+ "data-cms-block",
294
+ "data-cms-field",
295
+ "onKeydown"
296
+ ], S = { key: 1 }, C = /*#__PURE__*/ ((e, t) => {
297
+ let n = e.__vccOpts || e;
298
+ for (let [e, r] of t) n[e] = r;
299
+ return n;
300
+ })(/* @__PURE__ */ n({
301
+ __name: "CmsText",
302
+ props: {
303
+ block: {},
304
+ field: {}
305
+ },
306
+ setup(n) {
307
+ let u = n, d = r(y, {
308
+ messages: {},
309
+ editing: !1,
310
+ setText: () => {}
311
+ }), f = e(() => u.block.fields[u.field]), p = e(() => v(f.value, d.messages)), m = a(null);
312
+ function h() {
313
+ let e = m.value?.innerText.trim() ?? "";
314
+ e !== p.value && d.setText(u.block, u.field, f.value, e), m.value?.blur();
315
+ }
316
+ return (e, r) => s(d).editing ? (i(), t("span", {
317
+ key: 0,
318
+ ref_key: "el",
319
+ ref: m,
320
+ class: "cms-text cms-text--editing",
321
+ "data-cms-block": n.block.id,
322
+ "data-cms-field": n.field,
323
+ contenteditable: "plaintext-only",
324
+ role: "textbox",
325
+ tabindex: "0",
326
+ onBlur: h,
327
+ onKeydown: c(l(h, ["prevent"]), ["enter"])
328
+ }, o(p.value), 41, x)) : (i(), t("span", S, o(p.value), 1));
329
+ }
330
+ }), [["__scopeId", "data-v-57962fd1"]]);
331
+ //#endregion
332
+ export { y as CMS_CONTEXT, u as CORE_LOGIC_INPUTS, C as CmsText, d as NODE_SPECS, m as evaluate, p as evaluateGraph, g as isImage, _ as isLink, h as isTRef, v as text, f as toCards, b as useField };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@nubisco/cms-vue",
3
- "version": "1.0.0",
4
- "description": "Nubisco CMS content contract and evaluator. The Vue render kit follows.",
3
+ "version": "1.1.0",
4
+ "description": "Nubisco CMS content contract, evaluator, and Vue render kit.",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",
@@ -10,26 +10,35 @@
10
10
  "type": "module",
11
11
  "packageManager": "pnpm@10.33.0",
12
12
  "main": "./dist/index.js",
13
+ "module": "./dist/index.js",
13
14
  "types": "./dist/index.d.ts",
14
15
  "exports": {
15
16
  ".": {
16
17
  "types": "./dist/index.d.ts",
17
18
  "default": "./dist/index.js"
18
- }
19
+ },
20
+ "./style.css": "./dist/cms-vue.css"
19
21
  },
20
22
  "files": [
21
23
  "dist"
22
24
  ],
23
25
  "scripts": {
24
- "build": "tsc -p tsconfig.json",
25
- "types:check": "tsc --noEmit",
26
- "prepublishOnly": "pnpm run build"
26
+ "build": "vite build",
27
+ "types:check": "vue-tsc --noEmit"
28
+ },
29
+ "peerDependencies": {
30
+ "vue": "^3.4.0"
27
31
  },
28
32
  "devDependencies": {
29
33
  "@semantic-release/changelog": "^6.0.3",
30
34
  "@semantic-release/git": "^10.0.1",
35
+ "@vitejs/plugin-vue": "^6.0.5",
31
36
  "semantic-release": "^25.0.3",
32
- "typescript": "^5.9.3"
37
+ "typescript": "^5.9.3",
38
+ "vite": "^8.0.2",
39
+ "vite-plugin-dts": "^4.5.4",
40
+ "vue": "^3.5.30",
41
+ "vue-tsc": "^3.2.6"
33
42
  },
34
43
  "publishConfig": {
35
44
  "access": "public"
@@ -1,119 +0,0 @@
1
- /**
2
- * Content contract: the framework-agnostic shape of Nubisco CMS content.
3
- *
4
- * This is the crown jewel of the system. The CMS edits documents of this shape,
5
- * and any renderer (Vue first, others later) is just a function from these types
6
- * to a rendered page. Nothing here mentions Vue on purpose.
7
- *
8
- * Vocabulary: Fields (primitives) compose into Blocks (placeable units), which
9
- * are ordered inside Zones on a Page.
10
- */
11
- export type FieldType = 'text' | 'richtext' | 'number' | 'boolean' | 'image' | 'link' | 'color' | 'date' | 'select';
12
- /** A field's schema: what a Block declares it accepts. */
13
- export interface FieldSchema {
14
- type: FieldType;
15
- /** Editor-facing label. */
16
- label: string;
17
- help?: string;
18
- required?: boolean;
19
- /**
20
- * Whether the value is per-locale. Text/richtext default to true and are
21
- * stored by reference (see TRef) so Verba owns the translations. Media,
22
- * numbers, and booleans default to false.
23
- */
24
- localized?: boolean;
25
- /** Allowed values for `select`. */
26
- options?: string[];
27
- default?: unknown;
28
- /** Max length for text, or max value for number. */
29
- max?: number;
30
- }
31
- /**
32
- * A reference to an i18n key. Localized strings are never inlined into content;
33
- * they resolve from Verba / the site's locale JSON at render time. This keeps
34
- * Verba authoritative and the content documents small, and it matches how the
35
- * existing sites already use vue-i18n keys.
36
- */
37
- export interface TRef {
38
- $t: string;
39
- }
40
- export interface ImageValue {
41
- src: string;
42
- alt?: TRef;
43
- /** Intrinsic size, when known, to avoid layout shift. */
44
- w?: number;
45
- h?: number;
46
- }
47
- export interface LinkValue {
48
- href: string;
49
- label?: TRef;
50
- external?: boolean;
51
- }
52
- export type FieldValue = TRef | string | number | boolean | ImageValue | LinkValue;
53
- export type BlockKind =
54
- /** Fields only, assembled in the CMS. No app code required. */
55
- 'composed'
56
- /** Backed by an app component (anything with behavior, e.g. a form). */
57
- | 'coded';
58
- export type BlockCategory = 'content' | 'media' | 'form' | 'layout';
59
- export interface BlockVariation {
60
- id: string;
61
- label: string;
62
- /** Field values this variation presets (a footer subscribe vs a hero one). */
63
- presets?: Record<string, FieldValue>;
64
- }
65
- /** A named region inside a composed block that nests other blocks. */
66
- export interface SlotSchema {
67
- label: string;
68
- /** Block types allowed in this slot. Omit to allow any. */
69
- allow?: string[];
70
- }
71
- /**
72
- * A block type definition, registered once. The editor catalog, the inspector
73
- * fields, validation, and serialization all derive from this, mirroring how the
74
- * NubiscoUI Blueprint system derives everything from a NodeDefinition.
75
- *
76
- * Coded blocks map `type` to a real component through a per-framework registry
77
- * that lives in the renderer package, not in this contract.
78
- */
79
- export interface BlockDefinition {
80
- type: string;
81
- label: string;
82
- kind: BlockKind;
83
- category?: BlockCategory;
84
- icon?: string;
85
- fields: Record<string, FieldSchema>;
86
- variations?: BlockVariation[];
87
- slots?: Record<string, SlotSchema>;
88
- }
89
- /** A block as it appears in a content document. */
90
- export interface BlockInstance {
91
- /** Stable id: survives reorder, used for deep links and in-place edit targeting. */
92
- id: string;
93
- type: string;
94
- variation?: string;
95
- fields: Record<string, FieldValue>;
96
- /** Visibility logic. Absent means always visible. */
97
- when?: import('./logic').Condition;
98
- /** Nested blocks for composed blocks with slots. */
99
- slots?: Record<string, BlockInstance[]>;
100
- }
101
- /** An ordered list of blocks. Array order is render order and reorder order. */
102
- export interface Zone {
103
- blocks: BlockInstance[];
104
- }
105
- export interface PageDocument {
106
- route: string;
107
- meta?: {
108
- title?: TRef;
109
- description?: TRef;
110
- /** Page renders its own newsletter, so the footer one is suppressed. */
111
- ownNewsletter?: boolean;
112
- };
113
- /** Named zones, usually just `main`. */
114
- zones: Record<string, Zone>;
115
- /** Whole-page gate, e.g. a product feature flag. */
116
- when?: import('./logic').Condition;
117
- /** Logic graphs referenced by block/page conditions via { kind: 'graph', graphId }. */
118
- graphs?: Record<string, import('./logic').LogicGraph>;
119
- }
@@ -1,11 +0,0 @@
1
- /**
2
- * Content contract: the framework-agnostic shape of Nubisco CMS content.
3
- *
4
- * This is the crown jewel of the system. The CMS edits documents of this shape,
5
- * and any renderer (Vue first, others later) is just a function from these types
6
- * to a rendered page. Nothing here mentions Vue on purpose.
7
- *
8
- * Vocabulary: Fields (primitives) compose into Blocks (placeable units), which
9
- * are ordered inside Zones on a Page.
10
- */
11
- export {};
@@ -1,3 +0,0 @@
1
- /** The Nubisco CMS content contract. Framework-agnostic; renderers depend on this. */
2
- export * from './content';
3
- export * from './logic';
@@ -1,3 +0,0 @@
1
- /** The Nubisco CMS content contract. Framework-agnostic; renderers depend on this. */
2
- export * from './content';
3
- export * from './logic';
@@ -1,88 +0,0 @@
1
- /**
2
- * Logic contract: visibility and variation conditions.
3
- *
4
- * A Condition gates whether a Block or Page renders. It is either a simple
5
- * predicate, a boolean tree, or a reference to a NubiscoUI Blueprint graph for
6
- * the genuinely compound cases. Most content uses a simple predicate; the graph
7
- * is the escape hatch, not the default.
8
- *
9
- * Logic inputs are a registry. Adding a new input type (e.g. campaign source)
10
- * later is one LogicInputDefinition plus one Blueprint NodeDefinition. Nothing
11
- * in the engine or the content schema changes.
12
- */
13
- export type Op = 'is' | 'not' | 'in' | 'gte' | 'lte' | 'between';
14
- export type Condition = {
15
- kind: 'always';
16
- } | {
17
- kind: 'simple';
18
- /** A registered LogicInputDefinition id. */
19
- input: string;
20
- /** Input parameters, e.g. { flag: 'stagewright' } for featureFlag. */
21
- params?: Record<string, unknown>;
22
- /** Comparison for enum/number/date inputs. Boolean inputs need none. */
23
- op?: Op;
24
- value?: unknown;
25
- } | {
26
- kind: 'all';
27
- of: Condition[];
28
- } | {
29
- kind: 'any';
30
- of: Condition[];
31
- } | {
32
- kind: 'not';
33
- of: Condition;
34
- }
35
- /** Reference to a serialized Blueprint graph stored alongside the content. */
36
- | {
37
- kind: 'graph';
38
- graphId: string;
39
- };
40
- /**
41
- * Where a logic input can be evaluated. This is load-bearing for delivery:
42
- * - `build` inputs (flag, environment, locale) let a gated block prerender.
43
- * - `request` inputs (auth, region) force the block to be resolved at the edge
44
- * (a Worker) or revealed client-side. It cannot be baked.
45
- * A block whose condition mixes both is resolved at the most dynamic site.
46
- */
47
- export type ResolveAt = 'build' | 'request';
48
- export type LogicValueType = 'boolean' | 'enum' | 'number' | 'date';
49
- /**
50
- * A logic input type, registered once. The value is resolved by a host-provided
51
- * resolver keyed by `id`; this definition only declares the shape and where it
52
- * can run, so the visual editor and the evaluator are fully data-driven.
53
- */
54
- export type LogicKind = 'featureFlag' | 'environment' | 'auth' | 'region' | 'and' | 'or' | 'not' | 'visible';
55
- export interface LogicNode {
56
- id: string;
57
- kind: LogicKind;
58
- x: number;
59
- y: number;
60
- /** Flag key / environment value / region code, for the input nodes. */
61
- param?: string;
62
- }
63
- export interface GraphConnection {
64
- fromNode: string;
65
- fromPort: string;
66
- toNode: string;
67
- toPort: string;
68
- }
69
- export interface LogicGraph {
70
- nodes: LogicNode[];
71
- connections: GraphConnection[];
72
- }
73
- export interface LogicInputDefinition {
74
- id: string;
75
- label: string;
76
- valueType: LogicValueType;
77
- /** Parameters the author fills in, e.g. featureFlag needs a `flag`. */
78
- params?: Record<string, import('./content').FieldSchema>;
79
- resolveAt: ResolveAt;
80
- /** Allowed values for enum inputs (environment, region, locale). */
81
- enumValues?: string[];
82
- }
83
- /**
84
- * The initial catalog. Extend by appending a definition (and, for the visual
85
- * editor, a matching Blueprint NodeDefinition). `campaignSource` is the worked
86
- * example of a future input: append one entry with resolveAt: 'request'.
87
- */
88
- export declare const CORE_LOGIC_INPUTS: LogicInputDefinition[];
@@ -1,63 +0,0 @@
1
- /**
2
- * Logic contract: visibility and variation conditions.
3
- *
4
- * A Condition gates whether a Block or Page renders. It is either a simple
5
- * predicate, a boolean tree, or a reference to a NubiscoUI Blueprint graph for
6
- * the genuinely compound cases. Most content uses a simple predicate; the graph
7
- * is the escape hatch, not the default.
8
- *
9
- * Logic inputs are a registry. Adding a new input type (e.g. campaign source)
10
- * later is one LogicInputDefinition plus one Blueprint NodeDefinition. Nothing
11
- * in the engine or the content schema changes.
12
- */
13
- /**
14
- * The initial catalog. Extend by appending a definition (and, for the visual
15
- * editor, a matching Blueprint NodeDefinition). `campaignSource` is the worked
16
- * example of a future input: append one entry with resolveAt: 'request'.
17
- */
18
- export const CORE_LOGIC_INPUTS = [
19
- {
20
- id: 'featureFlag',
21
- label: 'Feature flag',
22
- valueType: 'boolean',
23
- params: { flag: { type: 'text', label: 'Flag key', required: true } },
24
- resolveAt: 'build',
25
- },
26
- {
27
- id: 'environment',
28
- label: 'Environment',
29
- valueType: 'enum',
30
- enumValues: ['staging', 'production'],
31
- resolveAt: 'build',
32
- },
33
- {
34
- id: 'locale',
35
- label: 'Locale',
36
- valueType: 'enum',
37
- enumValues: ['en', 'pt', 'es', 'fr'],
38
- resolveAt: 'build',
39
- },
40
- {
41
- id: 'schedule',
42
- label: 'Schedule window',
43
- valueType: 'date',
44
- params: {
45
- from: { type: 'date', label: 'From' },
46
- to: { type: 'date', label: 'To' },
47
- },
48
- resolveAt: 'build',
49
- },
50
- {
51
- id: 'auth',
52
- label: 'Signed in',
53
- valueType: 'boolean',
54
- resolveAt: 'request',
55
- },
56
- {
57
- id: 'region',
58
- label: 'Region',
59
- valueType: 'enum',
60
- enumValues: ['EU', 'NA', 'SA', 'AS', 'AF', 'OC'],
61
- resolveAt: 'request',
62
- },
63
- ];
@@ -1,15 +0,0 @@
1
- import type { Condition, LogicGraph, Op } from './contract';
2
- /**
3
- * Resolves one logic input to a boolean, given the author's params/op/value.
4
- * The host provides one resolver per registered input id (featureFlag,
5
- * environment, auth, region, ...). This is where build-time vs request-time
6
- * resolution actually happens; the contract only declares which is which.
7
- */
8
- export type InputResolver = (params: Record<string, unknown> | undefined, op: Op | undefined, value: unknown) => boolean;
9
- export type LogicEnv = Record<string, InputResolver>;
10
- /**
11
- * Evaluates a Condition tree to a visibility boolean. `graphs` supplies the
12
- * logic graphs referenced by { kind: 'graph' } conditions (stored on the page
13
- * document); a graph condition with no matching graph defaults to visible.
14
- */
15
- export declare function evaluate(condition: Condition | undefined, env: LogicEnv, graphs?: Record<string, LogicGraph>): boolean;
package/dist/evaluate.js DELETED
@@ -1,26 +0,0 @@
1
- import { evaluateGraph } from './graph';
2
- /**
3
- * Evaluates a Condition tree to a visibility boolean. `graphs` supplies the
4
- * logic graphs referenced by { kind: 'graph' } conditions (stored on the page
5
- * document); a graph condition with no matching graph defaults to visible.
6
- */
7
- export function evaluate(condition, env, graphs) {
8
- if (!condition || condition.kind === 'always')
9
- return true;
10
- switch (condition.kind) {
11
- case 'simple': {
12
- const resolve = env[condition.input];
13
- return resolve ? resolve(condition.params, condition.op, condition.value) : false;
14
- }
15
- case 'all':
16
- return condition.of.every((c) => evaluate(c, env, graphs));
17
- case 'any':
18
- return condition.of.some((c) => evaluate(c, env, graphs));
19
- case 'not':
20
- return !evaluate(condition.of, env, graphs);
21
- case 'graph': {
22
- const graph = graphs?.[condition.graphId];
23
- return graph ? evaluateGraph(graph, env).visible : true;
24
- }
25
- }
26
- }
package/dist/graph.d.ts DELETED
@@ -1,45 +0,0 @@
1
- import type { LogicGraph, LogicKind } from './contract';
2
- import type { LogicEnv } from './evaluate';
3
- /**
4
- * App-side logic for the graph form of a Condition (the data shapes live in the
5
- * contract). The node catalog, Blueprint card mapping, and evaluator are here.
6
- * Inputs (feature flag, environment, ...) feed gates (AND/OR/NOT) that feed a
7
- * single Visible sink; graphs are referenced from a condition as
8
- * { kind: 'graph', graphId }.
9
- */
10
- interface NodePort {
11
- id: string;
12
- label: string;
13
- type: 'input' | 'output';
14
- }
15
- interface NodeSpec {
16
- label: string;
17
- color: string;
18
- category: string;
19
- ports: NodePort[];
20
- /** Which parameter this node carries, if any. */
21
- param?: 'flag' | 'environment' | 'region';
22
- }
23
- export declare const NODE_SPECS: Record<LogicKind, NodeSpec>;
24
- export interface BlueprintCard {
25
- id: string;
26
- x: number;
27
- y: number;
28
- width: number;
29
- height: number;
30
- paint: {
31
- title: string;
32
- color: string;
33
- category: string;
34
- ports: NodePort[];
35
- };
36
- }
37
- /** Maps the logic graph to Blueprint card geometry + paint. */
38
- export declare function toCards(graph: LogicGraph): BlueprintCard[];
39
- export interface GraphResult {
40
- visible: boolean;
41
- nodeOut: Record<string, boolean>;
42
- }
43
- /** Evaluates the graph to the Visible sink's value, plus each node's output. */
44
- export declare function evaluateGraph(graph: LogicGraph, env: LogicEnv): GraphResult;
45
- export {};
package/dist/graph.js DELETED
@@ -1,130 +0,0 @@
1
- export const NODE_SPECS = {
2
- featureFlag: {
3
- label: 'Feature flag',
4
- color: '#6e6bd6',
5
- category: 'input',
6
- ports: [{ id: 'out', label: 'on', type: 'output' }],
7
- param: 'flag',
8
- },
9
- environment: {
10
- label: 'Environment',
11
- color: '#b9781e',
12
- category: 'input',
13
- ports: [{ id: 'out', label: 'is', type: 'output' }],
14
- param: 'environment',
15
- },
16
- auth: {
17
- label: 'Signed in',
18
- color: '#2c9560',
19
- category: 'input',
20
- ports: [{ id: 'out', label: 'yes', type: 'output' }],
21
- },
22
- region: {
23
- label: 'Region',
24
- color: '#3a86c8',
25
- category: 'input',
26
- ports: [{ id: 'out', label: 'in', type: 'output' }],
27
- param: 'region',
28
- },
29
- and: {
30
- label: 'AND',
31
- color: '#5a5a6a',
32
- category: 'gate',
33
- ports: [
34
- { id: 'a', label: 'a', type: 'input' },
35
- { id: 'b', label: 'b', type: 'input' },
36
- { id: 'out', label: 'out', type: 'output' },
37
- ],
38
- },
39
- or: {
40
- label: 'OR',
41
- color: '#5a5a6a',
42
- category: 'gate',
43
- ports: [
44
- { id: 'a', label: 'a', type: 'input' },
45
- { id: 'b', label: 'b', type: 'input' },
46
- { id: 'out', label: 'out', type: 'output' },
47
- ],
48
- },
49
- not: {
50
- label: 'NOT',
51
- color: '#5a5a6a',
52
- category: 'gate',
53
- ports: [
54
- { id: 'in', label: 'in', type: 'input' },
55
- { id: 'out', label: 'out', type: 'output' },
56
- ],
57
- },
58
- visible: {
59
- label: 'Visible',
60
- color: '#c0392b',
61
- category: 'output',
62
- ports: [{ id: 'in', label: 'show', type: 'input' }],
63
- },
64
- };
65
- /** Maps the logic graph to Blueprint card geometry + paint. */
66
- export function toCards(graph) {
67
- return graph.nodes.map((n) => {
68
- const spec = NODE_SPECS[n.kind];
69
- const title = n.param ? `${spec.label}: ${n.param}` : spec.label;
70
- return {
71
- id: n.id,
72
- x: n.x,
73
- y: n.y,
74
- width: 160,
75
- height: 52 + spec.ports.length * 8,
76
- paint: { title, color: spec.color, category: spec.category, ports: spec.ports },
77
- };
78
- });
79
- }
80
- /** Evaluates the graph to the Visible sink's value, plus each node's output. */
81
- export function evaluateGraph(graph, env) {
82
- const memo = {};
83
- const sourceOf = (nodeId, port) => graph.connections.find((c) => c.toNode === nodeId && c.toPort === port)?.fromNode;
84
- const inVal = (nodeId, port) => {
85
- const src = sourceOf(nodeId, port);
86
- return src ? out(src) : false;
87
- };
88
- function out(nodeId) {
89
- if (nodeId in memo)
90
- return memo[nodeId];
91
- memo[nodeId] = false; // break cycles defensively
92
- const node = graph.nodes.find((n) => n.id === nodeId);
93
- if (!node)
94
- return false;
95
- let v = false;
96
- switch (node.kind) {
97
- case 'featureFlag':
98
- v = env.featureFlag?.({ flag: node.param ?? '' }, undefined, undefined) ?? false;
99
- break;
100
- case 'environment':
101
- v = env.environment?.(undefined, 'is', node.param ?? 'staging') ?? false;
102
- break;
103
- case 'auth':
104
- v = env.auth?.(undefined, undefined, undefined) ?? false;
105
- break;
106
- case 'region':
107
- v = env.region?.(undefined, 'in', [node.param ?? '']) ?? false;
108
- break;
109
- case 'and':
110
- v = inVal(nodeId, 'a') && inVal(nodeId, 'b');
111
- break;
112
- case 'or':
113
- v = inVal(nodeId, 'a') || inVal(nodeId, 'b');
114
- break;
115
- case 'not':
116
- v = !inVal(nodeId, 'in');
117
- break;
118
- case 'visible':
119
- v = inVal(nodeId, 'in');
120
- break;
121
- }
122
- memo[nodeId] = v;
123
- return v;
124
- }
125
- const sink = graph.nodes.find((n) => n.kind === 'visible');
126
- const nodeOut = {};
127
- for (const n of graph.nodes)
128
- nodeOut[n.id] = out(n.id);
129
- return { visible: sink ? out(sink.id) : false, nodeOut };
130
- }
package/dist/resolve.d.ts DELETED
@@ -1,10 +0,0 @@
1
- import type { FieldValue, ImageValue, LinkValue, TRef } from './contract';
2
- export declare function isTRef(v: unknown): v is TRef;
3
- export declare function isImage(v: unknown): v is ImageValue;
4
- export declare function isLink(v: unknown): v is LinkValue;
5
- /**
6
- * Resolves a field value to display text. String refs ({ $t }) resolve from the
7
- * provided message table (Verba / locale JSON), falling back to the key so a
8
- * missing translation is visible rather than blank.
9
- */
10
- export declare function text(value: FieldValue | undefined, messages: Record<string, string>): string;
package/dist/resolve.js DELETED
@@ -1,25 +0,0 @@
1
- export function isTRef(v) {
2
- return typeof v === 'object' && v !== null && '$t' in v;
3
- }
4
- export function isImage(v) {
5
- return typeof v === 'object' && v !== null && 'src' in v;
6
- }
7
- export function isLink(v) {
8
- return typeof v === 'object' && v !== null && 'href' in v;
9
- }
10
- /**
11
- * Resolves a field value to display text. String refs ({ $t }) resolve from the
12
- * provided message table (Verba / locale JSON), falling back to the key so a
13
- * missing translation is visible rather than blank.
14
- */
15
- export function text(value, messages) {
16
- if (value == null)
17
- return '';
18
- if (typeof value === 'string')
19
- return value;
20
- if (typeof value === 'number' || typeof value === 'boolean')
21
- return String(value);
22
- if (isTRef(value))
23
- return messages[value.$t] ?? value.$t;
24
- return '';
25
- }