@streamline-pulse/formkrafter-core 0.20.0 → 0.22.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.
@@ -7,6 +7,7 @@ import type { BrickSpec } from "../utils/brick-spec";
7
7
  import type { BrickType } from "../utils/brick-type";
8
8
  import type { BrickBaseConfigs, CommonBrickProps } from "../utils/common-brick-props";
9
9
  import type { BrickMoldDropType } from "../utils/drop-type";
10
+ import type { FieldAnnotation } from "../review";
10
11
  export interface BrickProps<DataType, Configs extends BrickBaseConfigs, Styles> extends CommonBrickProps<Configs, Styles> {
11
12
  onConfigsChange?: (configs: BrickBaseConfigs & Record<string, unknown>, path?: string) => void;
12
13
  onStylesChange?: (styles: Record<string, unknown>, path?: string) => void;
@@ -22,6 +23,13 @@ export interface BrickProps<DataType, Configs extends BrickBaseConfigs, Styles>
22
23
  error?: string;
23
24
  disabled?: boolean;
24
25
  readOnly?: boolean;
26
+ /** A reviewer's note on this field, shown under the control. */
27
+ annotation?: FieldAnnotation;
28
+ /** Present in review mode: the controls to flag the field and comment it. */
29
+ review?: {
30
+ value: FieldAnnotation;
31
+ onChange: (next: FieldAnnotation) => void;
32
+ };
25
33
  locale?: string;
26
34
  children?: unknown;
27
35
  brickSpec?: BrickSpec;
package/dist/index.d.ts CHANGED
@@ -7,6 +7,8 @@ export { BrickSpec, buildValidationSchema, iterateBricks, iterateSchemaBricks, d
7
7
  export { getBrickData, wrapBrickData } from "./utils/brick-data";
8
8
  export { SelectOption, normalizeOptions } from "./utils/options";
9
9
  export { RecapItem, collectRecapItems } from "./utils/recap";
10
+ export { FieldDescriptor, CollectFieldsOptions, collectFields } from "./utils/fields";
11
+ export { FieldAnnotation, FieldAnnotations, flaggedKeys } from "./review";
10
12
  export { SpecIssue, SpecIssueCode, lintSpec } from "./utils/lint-spec";
11
13
  export { ensureBrickUids, stripBrickUids, stripUidsFromPatches } from "./ops/uids";
12
14
  export { interpolateTemplate, parseHeaderLines, appendSearchParam } from "./utils/remote";
package/dist/index.js CHANGED
@@ -17,7 +17,7 @@ var __toESM = (mod, isNodeMode, target) => {
17
17
  return cached;
18
18
  }
19
19
  target = mod != null ? __create(__getProtoOf(mod)) : {};
20
- const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
20
+ const to = isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
21
21
  if (mod && typeof mod === "object" || typeof mod === "function") {
22
22
  for (let key of __getOwnPropNames(mod))
23
23
  if (!__hasOwnProp.call(to, key))
@@ -199,9 +199,9 @@ var require_scope = __commonJS(function(exports) {
199
199
  }
200
200
  }
201
201
  var UsedValueState;
202
- (function(UsedValueState2) {
203
- UsedValueState2[UsedValueState2["Started"] = 0] = "Started";
204
- UsedValueState2[UsedValueState2["Completed"] = 1] = "Completed";
202
+ (function(UsedValueState) {
203
+ UsedValueState[UsedValueState["Started"] = 0] = "Started";
204
+ UsedValueState[UsedValueState["Completed"] = 1] = "Completed";
205
205
  })(UsedValueState || (exports.UsedValueState = UsedValueState = {}));
206
206
  exports.varKinds = {
207
207
  const: new code_1.Name("const"),
@@ -1183,9 +1183,9 @@ var require_util = __commonJS(function(exports) {
1183
1183
  }
1184
1184
  exports.useFunc = useFunc;
1185
1185
  var Type;
1186
- (function(Type2) {
1187
- Type2[Type2["Num"] = 0] = "Num";
1188
- Type2[Type2["Str"] = 1] = "Str";
1186
+ (function(Type) {
1187
+ Type[Type["Num"] = 0] = "Num";
1188
+ Type[Type["Str"] = 1] = "Str";
1189
1189
  })(Type || (exports.Type = Type = {}));
1190
1190
  function getErrorPath(dataProp, dataPropType, jsPropertySyntax) {
1191
1191
  if (dataProp instanceof codegen_1.Name) {
@@ -1455,9 +1455,9 @@ var require_dataType = __commonJS(function(exports) {
1455
1455
  var codegen_1 = require_codegen();
1456
1456
  var util_1 = require_util();
1457
1457
  var DataType;
1458
- (function(DataType2) {
1459
- DataType2[DataType2["Correct"] = 0] = "Correct";
1460
- DataType2[DataType2["Wrong"] = 1] = "Wrong";
1458
+ (function(DataType) {
1459
+ DataType[DataType["Correct"] = 0] = "Correct";
1460
+ DataType[DataType["Wrong"] = 1] = "Wrong";
1461
1461
  })(DataType || (exports.DataType = DataType = {}));
1462
1462
  function getSchemaTypes(schema) {
1463
1463
  const types = getJSONTypes(schema.type);
@@ -1853,8 +1853,8 @@ var require_keyword = __commonJS(function(exports) {
1853
1853
  gen.assign(valid, (0, codegen_1._)`${_await}${(0, code_1.callValidateCode)(cxt, validateRef, passCxt, passSchema)}`, def.modifying);
1854
1854
  }
1855
1855
  function reportErrs(errors) {
1856
- var _a2;
1857
- gen.if((0, codegen_1.not)((_a2 = def.valid) !== null && _a2 !== undefined ? _a2 : valid), errors);
1856
+ var _a;
1857
+ gen.if((0, codegen_1.not)((_a = def.valid) !== null && _a !== undefined ? _a : valid), errors);
1858
1858
  }
1859
1859
  }
1860
1860
  exports.funcKeywordCode = funcKeywordCode;
@@ -2635,8 +2635,8 @@ var require_validate = __commonJS(function(exports) {
2635
2635
  if (!this.allErrors)
2636
2636
  this.gen.if(cond);
2637
2637
  }
2638
- setParams(obj, assign2) {
2639
- if (assign2)
2638
+ setParams(obj, assign) {
2639
+ if (assign)
2640
2640
  Object.assign(this.params, obj);
2641
2641
  else
2642
2642
  this.params = obj;
@@ -3527,7 +3527,7 @@ var require_fast_uri = __commonJS(function(exports, module) {
3527
3527
  if (typeof uri === "string") {
3528
3528
  uri = normalizeString(uri, options);
3529
3529
  } else if (typeof uri === "object") {
3530
- uri = parse3(serialize(uri, options), options);
3530
+ uri = parse(serialize(uri, options), options);
3531
3531
  }
3532
3532
  return uri;
3533
3533
  }
@@ -3545,8 +3545,8 @@ var require_fast_uri = __commonJS(function(exports, module) {
3545
3545
  function resolveComponent(base, relative, options, skipNormalization) {
3546
3546
  const target = {};
3547
3547
  if (!skipNormalization) {
3548
- base = parse3(serialize(base, options), options);
3549
- relative = parse3(serialize(relative, options), options);
3548
+ base = parse(serialize(base, options), options);
3549
+ relative = parse(serialize(relative, options), options);
3550
3550
  }
3551
3551
  options = options || {};
3552
3552
  if (!options.tolerant && relative.scheme) {
@@ -3791,7 +3791,7 @@ var require_fast_uri = __commonJS(function(exports, module) {
3791
3791
  }
3792
3792
  return { parsed, malformedAuthorityOrPort };
3793
3793
  }
3794
- function parse3(uri, opts) {
3794
+ function parse(uri, opts) {
3795
3795
  return parseWithStatus(uri, opts).parsed;
3796
3796
  }
3797
3797
  function normalizeString(uri, opts) {
@@ -3820,7 +3820,7 @@ var require_fast_uri = __commonJS(function(exports, module) {
3820
3820
  resolveComponent,
3821
3821
  equal,
3822
3822
  serialize,
3823
- parse: parse3
3823
+ parse
3824
3824
  };
3825
3825
  module.exports = fastUri;
3826
3826
  module.exports.default = fastUri;
@@ -6001,9 +6001,9 @@ var require_types = __commonJS(function(exports) {
6001
6001
  Object.defineProperty(exports, "__esModule", { value: true });
6002
6002
  exports.DiscrError = undefined;
6003
6003
  var DiscrError;
6004
- (function(DiscrError2) {
6005
- DiscrError2["Tag"] = "tag";
6006
- DiscrError2["Mapping"] = "mapping";
6004
+ (function(DiscrError) {
6005
+ DiscrError["Tag"] = "tag";
6006
+ DiscrError["Mapping"] = "mapping";
6007
6007
  })(DiscrError || (exports.DiscrError = DiscrError = {}));
6008
6008
  });
6009
6009
 
@@ -7229,7 +7229,10 @@ var en = {
7229
7229
  "brick.row.name": "Row",
7230
7230
  "brick.column.name": "Column",
7231
7231
  "brick.stepper.name": "Stepper",
7232
- "brick.tabs.name": "Tabs"
7232
+ "brick.tabs.name": "Tabs",
7233
+ "review.incorrect": "Incorrect",
7234
+ "review.comment": "Comment for the person who corrects it",
7235
+ "review.flagged": "To correct"
7233
7236
  };
7234
7237
  var frFkTranslations = {
7235
7238
  "palette.search": "Rechercher une brique…",
@@ -7367,7 +7370,10 @@ var frFkTranslations = {
7367
7370
  "brick.row.name": "Ligne",
7368
7371
  "brick.column.name": "Colonne",
7369
7372
  "brick.stepper.name": "Étapes",
7370
- "brick.tabs.name": "Onglets"
7373
+ "brick.tabs.name": "Onglets",
7374
+ "review.incorrect": "Incorrect",
7375
+ "review.comment": "Commentaire pour la personne qui corrige",
7376
+ "review.flagged": "À corriger"
7371
7377
  };
7372
7378
  var GLOBAL_KEY = Symbol.for("formkrafter.i18n");
7373
7379
  var globalStore = globalThis;
@@ -7523,16 +7529,16 @@ var evalNode = (ctx, node) => {
7523
7529
  return;
7524
7530
  throw new Error(`Cannot call "${String(prop)}" of ${String(object)}`);
7525
7531
  }
7526
- const fn3 = object[prop];
7527
- if (typeof fn3 !== "function") {
7528
- if (node.optional === true && fn3 == null)
7532
+ const fn2 = object[prop];
7533
+ if (typeof fn2 !== "function") {
7534
+ if (node.optional === true && fn2 == null)
7529
7535
  return;
7530
7536
  throw new Error(`"${String(prop)}" is not a function`);
7531
7537
  }
7532
- if (fn3 === Function || fn3 === eval) {
7538
+ if (fn2 === Function || fn2 === eval) {
7533
7539
  throw new Error("This function is not allowed");
7534
7540
  }
7535
- return fn3.apply(object, args);
7541
+ return fn2.apply(object, args);
7536
7542
  }
7537
7543
  const fn2 = evalNode(ctx, callee);
7538
7544
  if (typeof fn2 !== "function") {
@@ -7664,8 +7670,8 @@ var evalNode = (ctx, node) => {
7664
7670
  if (property.type === "SpreadElement") {
7665
7671
  const spread = evalNode(ctx, property.argument);
7666
7672
  if (spread && typeof spread === "object") {
7667
- for (const [key2, value] of Object.entries(spread)) {
7668
- result[String(guardProp(key2))] = value;
7673
+ for (const [key, value] of Object.entries(spread)) {
7674
+ result[String(guardProp(key))] = value;
7669
7675
  }
7670
7676
  }
7671
7677
  continue;
@@ -8083,8 +8089,8 @@ var collectRecapItems = (spec, dataMap, locale, showEmpty, groupBySections = fal
8083
8089
  label,
8084
8090
  columns: inputs.map((input) => brickLabel(input, locale)),
8085
8091
  rows: rows.map((row) => inputs.map((input) => {
8086
- const raw2 = row?.[input.configs.key];
8087
- return isEmptyRecapValue(raw2) ? "—" : formatRecapValue(input, raw2);
8092
+ const raw = row?.[input.configs.key];
8093
+ return isEmptyRecapValue(raw) ? "—" : formatRecapValue(input, raw);
8088
8094
  }))
8089
8095
  });
8090
8096
  continue;
@@ -8115,6 +8121,64 @@ var collectRecapItems = (spec, dataMap, locale, showEmpty, groupBySections = fal
8115
8121
  }
8116
8122
  return items;
8117
8123
  };
8124
+ // lib/utils/fields.ts
8125
+ var staticOptions = (brick) => {
8126
+ const configs = brick.configs ?? {};
8127
+ const source = typeof configs.optionsSource === "string" ? configs.optionsSource : "static";
8128
+ if (source !== "static" || configs.options == null)
8129
+ return;
8130
+ const labelKey = typeof configs.labelKey === "string" ? configs.labelKey : "label";
8131
+ const valueKey = typeof configs.valueKey === "string" ? configs.valueKey : "value";
8132
+ const options = normalizeOptions(configs.options, labelKey, valueKey);
8133
+ return options.length ? options : undefined;
8134
+ };
8135
+ var describe = (brick, path, locale) => {
8136
+ const key = brick.configs?.key;
8137
+ const label = resolveLocalizedText(brick.configs?.label, locale);
8138
+ return {
8139
+ key,
8140
+ path,
8141
+ label: typeof label === "string" && label ? label : key,
8142
+ brick: brick.id,
8143
+ type: brick.type,
8144
+ dataType: brick.dataType,
8145
+ multiple: brick.type === "input" && brick.dataType === "array",
8146
+ required: (brick.validations ?? []).some((validation2) => validation2.validator === "required"),
8147
+ options: staticOptions(brick)
8148
+ };
8149
+ };
8150
+ var collectFields = (spec, locale, options = {}) => {
8151
+ const out = [];
8152
+ const walk = (brick, path, into) => {
8153
+ if (!brick)
8154
+ return;
8155
+ const key = brick.configs?.key;
8156
+ const named = typeof key === "string" && key !== "" && (options.includePrivate || !key.startsWith("_"));
8157
+ if (brick.type === "collection") {
8158
+ if (named) {
8159
+ const field = describe(brick, path, locale);
8160
+ field.columns = [];
8161
+ for (const [index, child] of (brick.children ?? []).entries())
8162
+ walk(child, `${path}.${index}`, field.columns);
8163
+ into.push(field);
8164
+ }
8165
+ return;
8166
+ }
8167
+ if (brick.type === "input") {
8168
+ if (named && brick.dataType && brick.dataType !== "void")
8169
+ into.push(describe(brick, path, locale));
8170
+ return;
8171
+ }
8172
+ if (brick.type === "panel") {
8173
+ for (const [index, child] of (brick.children ?? []).entries())
8174
+ walk(child, `${path}.${index}`, into);
8175
+ }
8176
+ };
8177
+ walk(spec, "0", out);
8178
+ return out;
8179
+ };
8180
+ // lib/review.ts
8181
+ var flaggedKeys = (annotations) => Object.entries(annotations ?? {}).filter(([, annotation]) => annotation?.incorrect === true).map(([key]) => key);
8118
8182
  // lib/utils/lint-spec.ts
8119
8183
  var isDataCarrying = (brick) => brick.type === "input" || brick.type === "collection";
8120
8184
  function lintSpec(spec) {
@@ -8502,8 +8566,8 @@ function addBrick(spec, brick, parentPath, index) {
8502
8566
  const parentPointer = pointerFromPath(parentPath);
8503
8567
  const value = toJsonValue(brick);
8504
8568
  if (!parent.children) {
8505
- const pointer2 = `${parentPointer}/children`;
8506
- return apply(spec, [{ op: "add", path: pointer2, value: [value] }], [{ op: "remove", path: pointer2 }]);
8569
+ const pointer = `${parentPointer}/children`;
8570
+ return apply(spec, [{ op: "add", path: pointer, value: [value] }], [{ op: "remove", path: pointer }]);
8507
8571
  }
8508
8572
  const position = Math.min(index ?? parent.children.length, parent.children.length);
8509
8573
  const pointer = `${parentPointer}/children/${position}`;
@@ -8818,7 +8882,7 @@ function convertComponent(component, ctx) {
8818
8882
  configs: {
8819
8883
  ...baseConfigs(component, ctx),
8820
8884
  optionsSource: "static",
8821
- options: emitOptions(staticOptions(component.values), component, ctx)
8885
+ options: emitOptions(staticOptions2(component.values), component, ctx)
8822
8886
  }
8823
8887
  })
8824
8888
  ];
@@ -8833,7 +8897,7 @@ function convertComponent(component, ctx) {
8833
8897
  configs: {
8834
8898
  ...baseConfigs(component, ctx),
8835
8899
  optionsSource: "static",
8836
- options: emitOptions(staticOptions(component.values), component, ctx)
8900
+ options: emitOptions(staticOptions2(component.values), component, ctx)
8837
8901
  }
8838
8902
  })
8839
8903
  ];
@@ -8921,7 +8985,7 @@ function convertSelect(component, ctx) {
8921
8985
  ctx.warn(`select "${component.key ?? "?"}" uses dataSrc "${component.dataSrc}" — converted to static options`);
8922
8986
  }
8923
8987
  configs.optionsSource = "static";
8924
- configs.options = emitOptions(staticOptions(component.data?.values ?? component.values), component, ctx);
8988
+ configs.options = emitOptions(staticOptions2(component.data?.values ?? component.values), component, ctx);
8925
8989
  }
8926
8990
  return withCommon(component, ctx, {
8927
8991
  type: "input",
@@ -8968,7 +9032,7 @@ function labelKeyFromTemplate(template) {
8968
9032
  const match = /item\.([a-zA-Z0-9_.]+)/.exec(template);
8969
9033
  return match?.[1];
8970
9034
  }
8971
- function staticOptions(values) {
9035
+ function staticOptions2(values) {
8972
9036
  return (values ?? []).map((option) => {
8973
9037
  if (!isPlainOptionObject(option))
8974
9038
  return scalarOption(option);
@@ -9214,6 +9278,7 @@ export {
9214
9278
  addBrick,
9215
9279
  appendSearchParam,
9216
9280
  buildValidationSchema,
9281
+ collectFields,
9217
9282
  collectRecapItems,
9218
9283
  convertFormioForm,
9219
9284
  defaultFormData,
@@ -9224,6 +9289,7 @@ export {
9224
9289
  expandSpec,
9225
9290
  fkT,
9226
9291
  fkTOr,
9292
+ flaggedKeys,
9227
9293
  frFkTranslations,
9228
9294
  getAffectedProperties,
9229
9295
  getBrickAt,
@@ -9257,5 +9323,5 @@ export {
9257
9323
  wrapBrickData
9258
9324
  };
9259
9325
 
9260
- //# debugId=96AA46B0772C95DC64756E2164756E21
9326
+ //# debugId=3FF11B6D83F7254764756E2164756E21
9261
9327
  //# sourceMappingURL=index.js.map