@jxsuite/schema 2.1.0 → 2.3.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.
package/src/schema.ts CHANGED
@@ -199,9 +199,17 @@ function buildEventHandlerProperties(eventHandlers: string[]) {
199
199
  }
200
200
 
201
201
  function buildCssProperties(cssProps: string[]) {
202
- const properties: Record<string, unknown> = {};
202
+ /* The authored `properties` come first so a `$`-prefixed metadata key survives: this function
203
+ REPLACES the block's properties rather than adding to them, so anything the hand-written schema
204
+ declared there was silently dropped — which is how `$description` validated as a number. */
205
+ const properties: Record<string, unknown> = { ...styleObjectSchema.properties };
203
206
  for (const name of cssProps) {
204
- properties[name] = { oneOf: [{ type: "string" }, { type: "number" }] };
207
+ /* A `{ $ref }` is a reactive VALUE, which the runtime has always resolved (spec.md §9.6) and
208
+ only the validator refused: `style: { fontFamily: { $ref: "$map/item/face" } }` reported
209
+ "must be string". It is what lets a row render in the face it names. */
210
+ properties[name] = {
211
+ oneOf: [{ type: "string" }, { type: "number" }, { $ref: "#/$defs/RefObject" }],
212
+ };
205
213
  }
206
214
  return properties;
207
215
  }
@@ -493,13 +501,29 @@ export async function generateSchema() {
493
501
  };
494
502
  }
495
503
 
504
+ /**
505
+ * `StyleObject` without the reactive-value branch, for a schema whose style block is emitted
506
+ * STATICALLY.
507
+ *
508
+ * A project's `style` block becomes the site stylesheet at build time, with no live scope to
509
+ * resolve against — so a `{ $ref }` there could never mean anything, and admitting it would
510
+ * validate a document the builder must silently drop. The document schema keeps the branch, because
511
+ * an element's style IS resolved against a scope.
512
+ */
513
+ const staticStyleObjectSchema = {
514
+ ...styleObjectSchema,
515
+ additionalProperties: {
516
+ anyOf: [{ type: "string" }, { type: "number" }, { $ref: "#/$defs/StyleObject" }],
517
+ },
518
+ } as const;
519
+
496
520
  // ─── Project Schema Generator ────────────────────────────────────────────────
497
521
 
498
522
  export function generateProjectSchema() {
499
523
  return {
500
524
  $defs: {
501
525
  ImageConfig: imageConfigSchema,
502
- StyleObject: styleObjectSchema,
526
+ StyleObject: staticStyleObjectSchema,
503
527
  },
504
528
  $id: "https://jxsuite.com/schema/project/v1",
505
529
  $schema: "https://json-schema.org/draft/2020-12/schema",
@@ -531,7 +555,7 @@ export function generateProjectCoreSchema() {
531
555
  ImageConfig: imageConfigSchema,
532
556
  JxFieldSchema: jxFieldSchemaDef,
533
557
  RelationshipRef: relationshipRefSchema,
534
- StyleObject: styleObjectSchema,
558
+ StyleObject: staticStyleObjectSchema,
535
559
  },
536
560
  $id: "https://jxsuite.com/schema/project/core/v2",
537
561
  $schema: "https://json-schema.org/draft/2020-12/schema",
package/types.ts CHANGED
@@ -149,11 +149,23 @@ export interface JxDispatchStatement {
149
149
  * One statement of a structured function body: a bare expression node in statement position
150
150
  * (mutation or `call`), a branch, a multiway branch, or an event dispatch.
151
151
  */
152
+ /** `{ stopPropagation: true }` — stop the handler's event at the current target (WHATWG DOM). */
153
+ export interface JxStopPropagationStatement {
154
+ stopPropagation: true;
155
+ }
156
+
157
+ /** `{ preventDefault: true }` — cancel the handler's event's default action (WHATWG DOM). */
158
+ export interface JxPreventDefaultStatement {
159
+ preventDefault: true;
160
+ }
161
+
152
162
  export type JxStatement =
153
163
  | JxExpressionNode
154
164
  | JxIfStatement
155
165
  | JxSwitchStatement
156
- | JxDispatchStatement;
166
+ | JxDispatchStatement
167
+ | JxStopPropagationStatement
168
+ | JxPreventDefaultStatement;
157
169
 
158
170
  /** A function declaration: inline `body` or external `$src`/`$export`. */
159
171
  export interface JxFunctionDef {
@@ -250,7 +262,14 @@ export interface CemEvent {
250
262
  export type RefObject = FromSchema<typeof refObjectSchema>;
251
263
 
252
264
  export interface JxStyle {
253
- [property: string]: string | number | JxStyle | undefined;
265
+ /**
266
+ * A declaration's value, a nested block, or SEVERAL blocks under one key.
267
+ *
268
+ * The array is what `@font-face` needs: an object's keys are unique, so a key can name a rule
269
+ * once, and that at-rule's identity is not in its key — a family with three weights has no other
270
+ * spelling. It means what writing the key that many times would mean, in order (spec.md §9.4).
271
+ */
272
+ [property: string]: string | number | RefObject | JxStyle | JxStyle[] | undefined;
254
273
  }
255
274
 
256
275
  /**
@@ -313,6 +332,11 @@ export interface JxMappedArray {
313
332
  map?: JxElement;
314
333
  filter?: Bindable<string>;
315
334
  sort?: Bindable<string>;
335
+ /**
336
+ * A `$map/item` pointer naming each row's identity (spec §10.4). Keyed rows keep their DOM node
337
+ * and effects across reorders, insertions and removals; absent, rows are keyed by index.
338
+ */
339
+ key?: JxRef;
316
340
  }
317
341
 
318
342
  export interface JxDocument extends JxElement {