@streamline-pulse/formkrafter-core 0.15.2 → 0.16.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/README.md CHANGED
@@ -4,7 +4,7 @@ The framework-agnostic heart of FormKrafter: form **specs**, immutable **mutatio
4
4
 
5
5
  ## The spec
6
6
 
7
- A form is a tree of `BrickSpec` nodes. Each brick has a `type` (`input`, `panel`, `collection`, `output`, `action`), an `id` (which registered brick renders it), `configs` (with a unique `uid` and a data `key`), plus optional `validations`, `rules`, `styles`, and `children`.
7
+ A form is a tree of `BrickSpec` nodes. Each brick has a `type` (`input`, `panel`, `collection`, `output`, `action`), an `id` (which registered brick renders it), `configs` (with a data `key`), plus optional `validations`, `rules`, `styles`, and `children`.
8
8
 
9
9
  ```mermaid
10
10
  flowchart TD
@@ -40,7 +40,7 @@ flowchart LR
40
40
  H -->|redo → apply patches| S1[spec']
41
41
  ```
42
42
 
43
- Available ops: `addBrick`, `removeBrick`, `moveBrick`, `duplicateBrick` (fresh uids), `updateBrickConfigs`, `updateBrickStyles`, `updateBrickValidations`, `updateBrickRules`. Addressing helpers: `getBrickAt(spec, path)`, `pointerOfUid(spec, uid)`, `iterateBricks(spec)`.
43
+ Available ops: `addBrick`, `removeBrick`, `moveBrick`, `duplicateBrick`, `updateBrickConfigs`, `updateBrickStyles`, `updateBrickValidations`, `updateBrickRules`. Addressing helpers: `getBrickAt(spec, path)`, `pointerFromPath(path)`, `iterateBricks(spec)`.
44
44
 
45
45
  Patches are plain RFC 6902 — persist them, sync them, audit them.
46
46
 
@@ -8,8 +8,8 @@ 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
10
  export interface BrickProps<DataType, Configs extends BrickBaseConfigs, Styles> extends CommonBrickProps<Configs, Styles> {
11
- onConfigsChange?: (configs: BrickBaseConfigs & Record<string, unknown>, uid?: string) => void;
12
- onStylesChange?: (styles: Record<string, unknown>, uid?: string) => void;
11
+ onConfigsChange?: (configs: BrickBaseConfigs & Record<string, unknown>, path?: string) => void;
12
+ onStylesChange?: (styles: Record<string, unknown>, path?: string) => void;
13
13
  data?: DataType;
14
14
  dataMap?: Record<string, unknown>;
15
15
  rootSpec?: BrickSpec;
@@ -26,9 +26,9 @@ export interface BrickProps<DataType, Configs extends BrickBaseConfigs, Styles>
26
26
  brickSpec?: BrickSpec;
27
27
  editable?: boolean;
28
28
  validations?: Validation[];
29
- onValidationsChange?: (validations: Validation[], uid?: string) => void;
29
+ onValidationsChange?: (validations: Validation[], path?: string) => void;
30
30
  rules?: Rule[];
31
- onRulesChange?: (rules: Rule[], uid?: string) => void;
31
+ onRulesChange?: (rules: Rule[], path?: string) => void;
32
32
  utils: Utils;
33
33
  }
34
34
  export declare abstract class Brick<DataType, Configs extends BrickBaseConfigs, Styles extends Record<string, unknown>> {
package/dist/index.d.ts CHANGED
@@ -27,7 +27,7 @@ export { DataSourceService, FetchDataSourceService } from "./services/data_sourc
27
27
  export { FileLike, UploadedFile, FileUploadService, FileUploadOptions, Base64FileUploadService, UrlFileUploadService, UrlFileUploadDefaults } from "./services/file_upload_service";
28
28
  export { LocalizedText, isLocalizedObject, resolveLocalizedText, resolveLocalizedRecord } from "./utils/localized-text";
29
29
  export { FkTranslations, setFkTranslations, fkT, fkTOr, frFkTranslations } from "./i18n";
30
- export { pointerFromPath, pointerOfUid, getBrickAt } from "./ops/pointer";
30
+ export { pointerFromPath, getBrickAt } from "./ops/pointer";
31
31
  export { SpecUpdate, addBrick, removeBrick, moveBrick, duplicateBrick, updateBrickConfigs, updateBrickStyles, updateBrickValidations, updateBrickRules } from "./ops/ops";
32
32
  export { SpecHistory } from "./ops/history";
33
33
  export type { Operation } from "fast-json-patch";
package/dist/index.js CHANGED
@@ -8414,19 +8414,14 @@ ${js}})();`;
8414
8414
  function pointerFromPath(path) {
8415
8415
  return path.split(".").slice(1).map((segment) => `/children/${segment}`).join("");
8416
8416
  }
8417
- function pointerOfUid(spec, uid) {
8418
- if (spec.configs?.uid === uid)
8419
- return "";
8420
- for (const [index, child] of (spec.children ?? []).entries()) {
8421
- const childPointer = pointerOfUid(child, uid);
8422
- if (childPointer !== undefined)
8423
- return `/children/${index}${childPointer}`;
8424
- }
8425
- return;
8426
- }
8427
8417
  function getBrickAt(spec, path) {
8418
+ const [root, ...segments] = path.split(".");
8419
+ if (root !== "0")
8420
+ return;
8428
8421
  let current = spec;
8429
- for (const segment of path.split(".").slice(1)) {
8422
+ for (const segment of segments) {
8423
+ if (!/^\d+$/.test(segment))
8424
+ return;
8430
8425
  current = current?.children?.[Number(segment)];
8431
8426
  }
8432
8427
  return current;
@@ -8448,16 +8443,10 @@ var requireBrickAt = (spec, path) => {
8448
8443
  throw new Error(`No brick at path "${path}"`);
8449
8444
  return brick;
8450
8445
  };
8451
- var requireBrickByUid = (spec, uid) => {
8452
- const pointer = pointerOfUid(spec, uid);
8453
- if (pointer === undefined)
8454
- throw new Error(`No brick with uid "${uid}"`);
8455
- let brick = spec;
8456
- for (const segment of pointer.split("/children/").slice(1)) {
8457
- brick = brick.children[Number(segment)];
8458
- }
8459
- return { pointer, brick };
8460
- };
8446
+ var requireBrickForUpdate = (spec, path) => ({
8447
+ pointer: pointerFromPath(path),
8448
+ brick: requireBrickAt(spec, path)
8449
+ });
8461
8450
  var toJsonValue = (value) => JSON.parse(JSON.stringify(value));
8462
8451
  function addBrick(spec, brick, parentPath, index) {
8463
8452
  const parent = requireBrickAt(spec, parentPath);
@@ -8527,22 +8516,22 @@ var setBrickSection = (spec, brickPointer, section, value, previous) => {
8527
8516
  }
8528
8517
  return apply(spec, [{ op: "replace", path: pointer, value }], [{ op: "replace", path: pointer, value: previous }]);
8529
8518
  };
8530
- function updateBrickConfigs(spec, uid, configs) {
8531
- const { pointer, brick } = requireBrickByUid(spec, uid);
8519
+ function updateBrickConfigs(spec, path, configs) {
8520
+ const { pointer, brick } = requireBrickForUpdate(spec, path);
8532
8521
  const merged = { ...brick.configs, ...configs };
8533
8522
  return setBrickSection(spec, pointer, "configs", merged, brick.configs);
8534
8523
  }
8535
- function updateBrickStyles(spec, uid, styles) {
8536
- const { pointer, brick } = requireBrickByUid(spec, uid);
8524
+ function updateBrickStyles(spec, path, styles) {
8525
+ const { pointer, brick } = requireBrickForUpdate(spec, path);
8537
8526
  const merged = { ...brick.styles, ...styles };
8538
8527
  return setBrickSection(spec, pointer, "styles", merged, brick.styles);
8539
8528
  }
8540
- function updateBrickValidations(spec, uid, validations) {
8541
- const { pointer, brick } = requireBrickByUid(spec, uid);
8529
+ function updateBrickValidations(spec, path, validations) {
8530
+ const { pointer, brick } = requireBrickForUpdate(spec, path);
8542
8531
  return setBrickSection(spec, pointer, "validations", validations, brick.validations);
8543
8532
  }
8544
- function updateBrickRules(spec, uid, rules) {
8545
- const { pointer, brick } = requireBrickByUid(spec, uid);
8533
+ function updateBrickRules(spec, path, rules) {
8534
+ const { pointer, brick } = requireBrickForUpdate(spec, path);
8546
8535
  return setBrickSection(spec, pointer, "rules", rules, brick.rules);
8547
8536
  }
8548
8537
  // lib/ops/history.ts
@@ -9181,7 +9170,6 @@ export {
9181
9170
  resolveLocalizedRecord,
9182
9171
  removeBrick,
9183
9172
  registerValidationMessages,
9184
- pointerOfUid,
9185
9173
  pointerFromPath,
9186
9174
  parseHeaderLines,
9187
9175
  normalizeOptions,
@@ -9219,5 +9207,5 @@ export {
9219
9207
  Base64FileUploadService
9220
9208
  };
9221
9209
 
9222
- //# debugId=F8E3FDC2C406A49364756E2164756E21
9210
+ //# debugId=BE1DBCBD4AB9F2FF64756E2164756E21
9223
9211
  //# sourceMappingURL=index.js.map