@powerhousedao/powerhouse-vetra-packages 6.1.0-dev.2 → 6.1.0-dev.21

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 (119) hide show
  1. package/dist/browser/assets/entry-Bzani6_n.js +313 -0
  2. package/dist/browser/assets/projection-entry-Bpu-8SnI.js +406 -0
  3. package/dist/browser/{dist-DOMEWT3x.js → connect-ZnLjvmRt.js} +13013 -10302
  4. package/dist/browser/connect-ZnLjvmRt.js.map +1 -0
  5. package/dist/browser/dist-C1nRM9t2.js +3768 -0
  6. package/dist/browser/dist-C1nRM9t2.js.map +1 -0
  7. package/dist/browser/{schemas-Bqem6NRm.js → dist-CXoKspdx.js} +131 -2
  8. package/dist/browser/dist-CXoKspdx.js.map +1 -0
  9. package/dist/browser/dist-D8H48e8N.js +2692 -0
  10. package/dist/browser/dist-D8H48e8N.js.map +1 -0
  11. package/dist/browser/{dist-CC1E3l2O.js → dist-DLFI75Zd.js} +37 -9
  12. package/dist/browser/dist-DLFI75Zd.js.map +1 -0
  13. package/dist/browser/{dist-DQgJ8n4d.js → document-drive-oqv68jDU.js} +432 -290
  14. package/dist/browser/document-drive-oqv68jDU.js.map +1 -0
  15. package/dist/browser/document-models/index.js +1 -1
  16. package/dist/browser/{documents-Bpu0aSLb.js → documents-D4ek7Ubv.js} +3 -3
  17. package/dist/browser/{documents-Bpu0aSLb.js.map → documents-D4ek7Ubv.js.map} +1 -1
  18. package/dist/browser/{editor-B3yz7YdR.js → editor-CoTq6fqT.js} +32 -31
  19. package/dist/browser/editor-CoTq6fqT.js.map +1 -0
  20. package/dist/browser/{editor-Dm_73jiz.js → editor-DC3bigBu.js} +5 -5
  21. package/dist/browser/{editor-Dm_73jiz.js.map → editor-DC3bigBu.js.map} +1 -1
  22. package/dist/browser/editors/document-model-editor/module.js +1 -1
  23. package/dist/browser/editors/generic-drive-explorer/index.js +6 -6
  24. package/dist/browser/editors/generic-drive-explorer/index.js.map +1 -1
  25. package/dist/browser/editors/generic-drive-explorer/module.js +1 -1
  26. package/dist/browser/{folder-view-H2ov-zId.js → folder-view-DmYBf2pP.js} +13 -12
  27. package/dist/browser/folder-view-DmYBf2pP.js.map +1 -0
  28. package/dist/browser/{graphql-editor-CnaQ3XWx.js → graphql-editor-CiGd_Li7.js} +15 -7
  29. package/dist/browser/{graphql-editor-CnaQ3XWx.js.map → graphql-editor-CiGd_Li7.js.map} +1 -1
  30. package/dist/{node/hooks-Lbsf6g-v.mjs → browser/hooks-CORHBNHb.js} +6 -4
  31. package/dist/browser/{hooks-Beny0xpe.js.map → hooks-CORHBNHb.js.map} +1 -1
  32. package/dist/browser/index.js +2 -2
  33. package/dist/{node/json-editor-CVGgDVh2.mjs → browser/json-editor-sEqd5piI.js} +12 -4
  34. package/dist/browser/json-editor-sEqd5piI.js.map +1 -0
  35. package/dist/browser/{style-DYS_RFSN.js → linting-Dn6pXRkK.js} +7 -14
  36. package/dist/browser/linting-Dn6pXRkK.js.map +1 -0
  37. package/dist/browser/{parser-B0sh99Kk.js → parser-CkF6Qt8V.js} +1 -1
  38. package/dist/browser/{parser-B0sh99Kk.js.map → parser-CkF6Qt8V.js.map} +1 -1
  39. package/dist/browser/{schema-context-C0GpuR27.js → schema-context-DY-GEGnY.js} +4 -4
  40. package/dist/browser/schema-context-DY-GEGnY.js.map +1 -0
  41. package/dist/browser/state-schemas-DJmzG_M8.js +308 -0
  42. package/dist/browser/state-schemas-DJmzG_M8.js.map +1 -0
  43. package/dist/node/{dist-1kPMPFPD.mjs → connect-BLC4PXD9.mjs} +13953 -11229
  44. package/dist/node/connect-BLC4PXD9.mjs.map +1 -0
  45. package/dist/node/dist-BeZaEP6S.mjs +2692 -0
  46. package/dist/node/dist-BeZaEP6S.mjs.map +1 -0
  47. package/dist/node/dist-Bm05eoTg.mjs +3769 -0
  48. package/dist/node/dist-Bm05eoTg.mjs.map +1 -0
  49. package/dist/node/{tslib.es6-DwVpIYUS.mjs → dist-Cn3iExnV.mjs} +489 -3
  50. package/dist/node/dist-Cn3iExnV.mjs.map +1 -0
  51. package/dist/node/{schemas-Cb8uEF9u.mjs → dist-fA4EItr0.mjs} +131 -2
  52. package/dist/node/dist-fA4EItr0.mjs.map +1 -0
  53. package/dist/node/{dist-Bz4SgEHs.mjs → document-drive-sM33juXr.mjs} +432 -290
  54. package/dist/node/document-drive-sM33juXr.mjs.map +1 -0
  55. package/dist/node/document-models/index.mjs +1 -1
  56. package/dist/node/{documents-BWJpUm9f.mjs → documents-BFBPmyw1.mjs} +3 -3
  57. package/dist/node/{documents-BWJpUm9f.mjs.map → documents-BFBPmyw1.mjs.map} +1 -1
  58. package/dist/node/{editor-W8QOlGXD.mjs → editor-BFBa9nsO.mjs} +32 -31
  59. package/dist/node/editor-BFBa9nsO.mjs.map +1 -0
  60. package/dist/node/{editor-BaXuDsby.mjs → editor-BrS98lEH.mjs} +5 -5
  61. package/dist/node/{editor-BaXuDsby.mjs.map → editor-BrS98lEH.mjs.map} +1 -1
  62. package/dist/node/editors/document-model-editor/module.mjs +1 -1
  63. package/dist/node/editors/generic-drive-explorer/index.mjs +6 -6
  64. package/dist/node/editors/generic-drive-explorer/index.mjs.map +1 -1
  65. package/dist/node/editors/generic-drive-explorer/module.mjs +1 -1
  66. package/dist/node/{folder-view-B0FNXbc0.mjs → folder-view-DHph3Yuu.mjs} +13 -12
  67. package/dist/node/folder-view-DHph3Yuu.mjs.map +1 -0
  68. package/dist/node/{graphql-Du2phcBf.mjs → graphql-DskHmkMe.mjs} +2 -2
  69. package/dist/node/{graphql-Du2phcBf.mjs.map → graphql-DskHmkMe.mjs.map} +1 -1
  70. package/dist/node/{graphql-editor-D1koK5kR.mjs → graphql-editor-CPq7oIbf.mjs} +14 -6
  71. package/dist/node/{graphql-editor-D1koK5kR.mjs.map → graphql-editor-CPq7oIbf.mjs.map} +1 -1
  72. package/dist/{browser/hooks-Beny0xpe.js → node/hooks-DJrjfVaS.mjs} +6 -4
  73. package/dist/node/{hooks-Lbsf6g-v.mjs.map → hooks-DJrjfVaS.mjs.map} +1 -1
  74. package/dist/node/index.mjs +2 -2
  75. package/dist/{browser/json-editor-h3cffF6X.js → node/json-editor-L32CP7TS.mjs} +12 -4
  76. package/dist/node/json-editor-L32CP7TS.mjs.map +1 -0
  77. package/dist/node/{style-CxHkfyna.mjs → linting-Dx50GuLN.mjs} +7 -14
  78. package/dist/node/linting-Dx50GuLN.mjs.map +1 -0
  79. package/dist/node/{schema-context-mLgEY1Hh.mjs → schema-context-CX5ml_9t.mjs} +4 -4
  80. package/dist/node/schema-context-CX5ml_9t.mjs.map +1 -0
  81. package/dist/node/state-schemas-XTTjQZOe.mjs +309 -0
  82. package/dist/node/state-schemas-XTTjQZOe.mjs.map +1 -0
  83. package/package.json +10 -10
  84. package/style.css +1 -0
  85. package/dist/browser/connect-CKdlDSUw.js +0 -9460
  86. package/dist/browser/connect-CKdlDSUw.js.map +0 -1
  87. package/dist/browser/dist-BXygvBtd.js +0 -132
  88. package/dist/browser/dist-BXygvBtd.js.map +0 -1
  89. package/dist/browser/dist-CC1E3l2O.js.map +0 -1
  90. package/dist/browser/dist-DOMEWT3x.js.map +0 -1
  91. package/dist/browser/dist-DQgJ8n4d.js.map +0 -1
  92. package/dist/browser/editor-B3yz7YdR.js.map +0 -1
  93. package/dist/browser/folder-view-H2ov-zId.js.map +0 -1
  94. package/dist/browser/json-editor-h3cffF6X.js.map +0 -1
  95. package/dist/browser/schema-context-C0GpuR27.js.map +0 -1
  96. package/dist/browser/schemas-Bqem6NRm.js.map +0 -1
  97. package/dist/browser/state-schemas-C5NPeV6-.js +0 -674
  98. package/dist/browser/state-schemas-C5NPeV6-.js.map +0 -1
  99. package/dist/browser/style-DYS_RFSN.js.map +0 -1
  100. package/dist/browser/tslib.es6-DRuVAsR8.js +0 -32
  101. package/dist/browser/tslib.es6-DRuVAsR8.js.map +0 -1
  102. package/dist/node/connect-SGvLzr5K.mjs +0 -9475
  103. package/dist/node/connect-SGvLzr5K.mjs.map +0 -1
  104. package/dist/node/dist-1kPMPFPD.mjs.map +0 -1
  105. package/dist/node/dist-BQTIepWC.mjs +0 -132
  106. package/dist/node/dist-BQTIepWC.mjs.map +0 -1
  107. package/dist/node/dist-Bz4SgEHs.mjs.map +0 -1
  108. package/dist/node/dist-Cay1iRRr.mjs +0 -491
  109. package/dist/node/dist-Cay1iRRr.mjs.map +0 -1
  110. package/dist/node/editor-W8QOlGXD.mjs.map +0 -1
  111. package/dist/node/folder-view-B0FNXbc0.mjs.map +0 -1
  112. package/dist/node/json-editor-CVGgDVh2.mjs.map +0 -1
  113. package/dist/node/schema-context-mLgEY1Hh.mjs.map +0 -1
  114. package/dist/node/schemas-Cb8uEF9u.mjs.map +0 -1
  115. package/dist/node/state-schemas-DAthoEEk.mjs +0 -675
  116. package/dist/node/state-schemas-DAthoEEk.mjs.map +0 -1
  117. package/dist/node/style-CxHkfyna.mjs.map +0 -1
  118. package/dist/node/tslib.es6-DwVpIYUS.mjs.map +0 -1
  119. package/dist/style.css +0 -906
@@ -1,5 +1,4 @@
1
- import { E as __toESM, a as boolean, c as literal, f as string, g as ZodError, i as array, l as number, m as unknown, p as union, r as any, s as lazy, t as _enum, u as object, x as __commonJSMin } from "./schemas-Cb8uEF9u.mjs";
2
- import { r as pascalCase } from "./dist-BQTIepWC.mjs";
1
+ import { E as __commonJSMin, _ as string, c as any, f as lazy, h as object, j as __toESM, l as array, m as number, n as constantCase, o as _enum, p as literal, r as pascalCase, u as boolean, v as union, x as ZodError, y as unknown } from "./dist-fA4EItr0.mjs";
3
2
  import { createRequire } from "module";
4
3
  //#endregion
5
4
  //#region ../../node_modules/.pnpm/safe-stable-stringify@2.5.0/node_modules/safe-stable-stringify/esm/wrapper.js
@@ -591,7 +590,7 @@ function isBE() {
591
590
  return new Uint8Array(new Uint16Array([65279]).buffer)[0] === 254;
592
591
  }
593
592
  //#endregion
594
- //#region ../shared/dist/utils-bCWnsmtD.js
593
+ //#region ../shared/dist/utils-DKOFCM0Q.js
595
594
  const hashBrowser = (data, algorithm = "sha1", encoding = "base64", _params) => {
596
595
  if (!["sha1"].includes(algorithm)) throw new Error(`Hashing algorithm not supported: "${algorithm}". Available: sha1`);
597
596
  if (!["base64", "hex"].includes(encoding)) throw new Error(`Hash encoding not supported: "${encoding}". Available: base64, hex`);
@@ -4385,16 +4384,72 @@ function isDocumentAction(action) {
4385
4384
  ].includes(action.type);
4386
4385
  }
4387
4386
  /**
4388
- * Important note: it is the responsibility of the caller to set the document type
4389
- * on the header.
4387
+ * The document-scope operations a reactor mints on `create`, so a standalone
4388
+ * document carries its initial state when exported outside a reactor.
4390
4389
  */
4391
- function baseCreateDocument(createState, initialState) {
4390
+ function createDocumentScopeOperations(header, state) {
4391
+ const createInput = {
4392
+ model: header.documentType,
4393
+ version: 0,
4394
+ documentId: header.id,
4395
+ signing: {
4396
+ signature: header.id,
4397
+ publicKey: header.sig.publicKey,
4398
+ nonce: header.sig.nonce,
4399
+ createdAtUtcIso: header.createdAtUtcIso,
4400
+ documentType: header.documentType
4401
+ },
4402
+ slug: header.slug,
4403
+ name: header.name,
4404
+ branch: header.branch,
4405
+ meta: header.meta,
4406
+ protocolVersions: header.protocolVersions ?? { "base-reducer": 2 }
4407
+ };
4408
+ const upgradeInput = {
4409
+ model: header.documentType,
4410
+ fromVersion: 0,
4411
+ toVersion: state.document.version,
4412
+ documentId: header.id,
4413
+ initialState: state
4414
+ };
4415
+ return [{
4416
+ id: generateId(),
4417
+ type: "CREATE_DOCUMENT",
4418
+ scope: "document",
4419
+ timestampUtcMs: header.createdAtUtcIso,
4420
+ input: createInput
4421
+ }, {
4422
+ id: generateId(),
4423
+ type: "UPGRADE_DOCUMENT",
4424
+ scope: "document",
4425
+ timestampUtcMs: header.createdAtUtcIso,
4426
+ input: upgradeInput
4427
+ }].map((action, index) => ({
4428
+ ...action,
4429
+ action,
4430
+ id: deriveOperationId(header.id, "document", header.branch, action.id),
4431
+ hash: "",
4432
+ error: void 0,
4433
+ index,
4434
+ skip: 0
4435
+ }));
4436
+ }
4437
+ /**
4438
+ * Creates a new document. When `documentType` is given the header is stamped
4439
+ * with it and the document-scope operations are seeded.
4440
+ */
4441
+ function baseCreateDocument(createState, initialState, documentType = "") {
4392
4442
  const state = createState(initialState);
4443
+ const header = createPresignedHeader(generateId(), documentType);
4393
4444
  return {
4394
- header: createPresignedHeader(),
4445
+ header,
4395
4446
  state,
4396
4447
  initialState: state,
4397
- operations: {
4448
+ operations: documentType ? {
4449
+ global: [],
4450
+ local: [],
4451
+ document: createDocumentScopeOperations(header, state)
4452
+ } : {
4398
4453
  global: [],
4399
4454
  local: []
4400
4455
  },
@@ -5092,6 +5147,15 @@ const RESERVED_OPERATION_NAMES = [
5092
5147
  "NOOP"
5093
5148
  ];
5094
5149
  /**
5150
+ * Operation names become the literal action `type` string at runtime and the
5151
+ * key for codegen's action union. They must be SCREAMING_SNAKE_CASE so the
5152
+ * generated TypeScript is valid.
5153
+ */
5154
+ const OPERATION_NAME_PATTERN = /^[A-Z][A-Z0-9_]*$/;
5155
+ function isValidOperationNameFormat(name) {
5156
+ return OPERATION_NAME_PATTERN.test(name);
5157
+ }
5158
+ /**
5095
5159
  * Check if name conflicts with base reducer actions (case-insensitive).
5096
5160
  */
5097
5161
  function isReservedOperationName(name) {
@@ -5121,6 +5185,11 @@ function getAllOperationNames(state, excludeOperationId) {
5121
5185
  */
5122
5186
  function validateOperationName(name, state, excludeOperationId) {
5123
5187
  if (!name) return;
5188
+ if (!isValidOperationNameFormat(name)) {
5189
+ const suggestion = constantCase(name);
5190
+ const hint = suggestion && suggestion !== name && isValidOperationNameFormat(suggestion) ? ` Did you mean "${suggestion}"?` : "";
5191
+ throw new Error(`Operation name "${name}" is invalid. Names must be SCREAMING_SNAKE_CASE (matching ${OPERATION_NAME_PATTERN.source}).${hint}`);
5192
+ }
5124
5193
  const upperName = name.toUpperCase();
5125
5194
  if (isReservedOperationName(name)) throw new Error(`Operation name "${name}" is reserved. Please use a different name.`);
5126
5195
  if (getAllOperationNames(state, excludeOperationId).includes(upperName)) throw new Error(`Operation name "${name}" is already used by another operation. Operation names must be unique across all modules.`);
@@ -5216,6 +5285,60 @@ function findOperationOrThrow(state, operationId) {
5216
5285
  }
5217
5286
  throw new Error(`Operation "${operationId}" not found in the latest specification`);
5218
5287
  }
5288
+ /**
5289
+ * Find an operation error by id across all operations in the latest
5290
+ * specification, or throw. Throws on a duplicate id too: setters act on a
5291
+ * single error, so an ambiguous id must fail loudly rather than mutate an
5292
+ * arbitrary match.
5293
+ */
5294
+ function findOperationErrorOrThrow(state, errorId) {
5295
+ const matches = state.specifications[state.specifications.length - 1]?.modules.flatMap((mod) => mod.operations.flatMap((op) => op.errors.filter((e) => e.id === errorId))) ?? [];
5296
+ if (matches.length === 0) throw new Error(`Operation error "${errorId}" not found in the latest specification`);
5297
+ if (matches.length > 1) throw new Error(`Operation error "${errorId}" is duplicated in the latest specification`);
5298
+ return matches[0];
5299
+ }
5300
+ /**
5301
+ * Find an operation example (code example) by id across all operations in the
5302
+ * latest specification, or throw. Throws on a duplicate id for the same reason
5303
+ * as findOperationErrorOrThrow.
5304
+ */
5305
+ function findOperationExampleOrThrow(state, exampleId) {
5306
+ const matches = state.specifications[state.specifications.length - 1]?.modules.flatMap((mod) => mod.operations.flatMap((op) => op.examples.filter((e) => e.id === exampleId))) ?? [];
5307
+ if (matches.length === 0) throw new Error(`Operation example "${exampleId}" not found in the latest specification`);
5308
+ if (matches.length > 1) throw new Error(`Operation example "${exampleId}" is duplicated in the latest specification`);
5309
+ return matches[0];
5310
+ }
5311
+ /**
5312
+ * Assert no module in the latest specification already uses `id`. Modules are
5313
+ * targeted by id by the setter/delete/reorder reducers, so a duplicate id makes
5314
+ * those operations ambiguous.
5315
+ */
5316
+ function assertModuleIdUnique(state, id) {
5317
+ if (state.specifications[state.specifications.length - 1]?.modules.some((m) => m.id === id)) throw new Error(`Module "${id}" already exists in the latest specification`);
5318
+ }
5319
+ /**
5320
+ * Assert no operation in the latest specification already uses `id`. Operations
5321
+ * are targeted by id across all modules, so the id must be unique document-wide.
5322
+ */
5323
+ function assertOperationIdUnique(state, id) {
5324
+ if (state.specifications[state.specifications.length - 1]?.modules.some((m) => m.operations.some((o) => o.id === id))) throw new Error(`Operation "${id}" already exists in the latest specification`);
5325
+ }
5326
+ /**
5327
+ * Assert no operation error in the latest specification already uses `id`.
5328
+ * Error ids are targeted document-wide by the setter/delete reducers, so the id
5329
+ * must be unique to keep those operations unambiguous.
5330
+ */
5331
+ function assertOperationErrorIdUnique(state, id) {
5332
+ if (state.specifications[state.specifications.length - 1]?.modules.some((m) => m.operations.some((o) => o.errors.some((e) => e.id === id)))) throw new Error(`Operation error "${id}" already exists in the latest specification`);
5333
+ }
5334
+ /**
5335
+ * Assert no operation example in the latest specification already uses `id`.
5336
+ * Example ids are targeted document-wide by the update/delete reducers, so the
5337
+ * id must be unique to keep those operations unambiguous.
5338
+ */
5339
+ function assertOperationExampleIdUnique(state, id) {
5340
+ if (state.specifications[state.specifications.length - 1]?.modules.some((m) => m.operations.some((o) => o.examples.some((e) => e.id === id)))) throw new Error(`Operation example "${id}" already exists in the latest specification`);
5341
+ }
5219
5342
  function validateOperations(operations) {
5220
5343
  const errors = [];
5221
5344
  const scopes = Object.keys(operations);
@@ -5238,10 +5361,22 @@ function validateOperations(operations) {
5238
5361
  }
5239
5362
  return errors;
5240
5363
  }
5241
- function sorter(order) {
5242
- const mapping = {};
5243
- order.forEach((key, index) => mapping[key] = index);
5244
- return (a, b) => (mapping[b.id] || 999999) - (mapping[a.id] || 999999);
5364
+ /**
5365
+ * Reorder `items` by the position of their id in `order`. Ids not listed in
5366
+ * `order` keep their relative position after the listed ones. Throws if `order`
5367
+ * references an id that isn't present, so a stale or mistyped id fails loudly
5368
+ * instead of silently producing an arbitrary order.
5369
+ */
5370
+ function orderBy(items, order) {
5371
+ const ids = new Set(items.map((item) => item.id));
5372
+ for (const id of order) if (!ids.has(id)) throw new Error(`Cannot reorder: unknown id "${id}"`);
5373
+ const rank = new Map(order.map((id, index) => [id, index]));
5374
+ return items.map((item, index) => ({
5375
+ item,
5376
+ index
5377
+ })).sort((a, b) => {
5378
+ return (rank.get(a.item.id) ?? Number.MAX_SAFE_INTEGER) - (rank.get(b.item.id) ?? Number.MAX_SAFE_INTEGER) || a.index - b.index;
5379
+ }).map(({ item }) => item);
5245
5380
  }
5246
5381
  const documentModelHeaderReducer = {
5247
5382
  setModelNameOperation(state, action) {
@@ -5273,6 +5408,7 @@ const documentModelHeaderReducer = {
5273
5408
  };
5274
5409
  const documentModelModuleReducer = {
5275
5410
  addModuleOperation(state, action) {
5411
+ assertModuleIdUnique(state, action.input.id);
5276
5412
  state.specifications[state.specifications.length - 1].modules.push({
5277
5413
  id: action.input.id,
5278
5414
  name: action.input.name,
@@ -5281,24 +5417,28 @@ const documentModelModuleReducer = {
5281
5417
  });
5282
5418
  },
5283
5419
  setModuleNameOperation(state, action) {
5284
- const latestSpec = state.specifications[state.specifications.length - 1];
5285
- for (let i = 0; i < latestSpec.modules.length; i++) if (latestSpec.modules[i].id === action.input.id) latestSpec.modules[i].name = action.input.name || "";
5420
+ const targetModule = findModuleOrThrow(state, action.input.id);
5421
+ targetModule.name = action.input.name || "";
5286
5422
  },
5287
5423
  setModuleDescriptionOperation(state, action) {
5288
- const latestSpec = state.specifications[state.specifications.length - 1];
5289
- for (let i = 0; i < latestSpec.modules.length; i++) if (latestSpec.modules[i].id === action.input.id) latestSpec.modules[i].description = action.input.description || "";
5424
+ const targetModule = findModuleOrThrow(state, action.input.id);
5425
+ targetModule.description = action.input.description || "";
5290
5426
  },
5291
5427
  deleteModuleOperation(state, action) {
5428
+ findModuleOrThrow(state, action.input.id);
5292
5429
  const latestSpec = state.specifications[state.specifications.length - 1];
5293
5430
  latestSpec.modules = latestSpec.modules.filter((m) => m.id != action.input.id);
5294
5431
  },
5295
5432
  reorderModulesOperation(state, action) {
5296
- state.specifications[state.specifications.length - 1].modules.sort(sorter(action.input.order));
5433
+ const latestSpec = state.specifications[state.specifications.length - 1];
5434
+ latestSpec.modules = orderBy(latestSpec.modules, action.input.order);
5297
5435
  }
5298
5436
  };
5299
5437
  const documentModelOperationErrorReducer = {
5300
5438
  addOperationErrorOperation(state, action) {
5301
- findOperationOrThrow(state, action.input.operationId).errors.push({
5439
+ const targetOp = findOperationOrThrow(state, action.input.operationId);
5440
+ assertOperationErrorIdUnique(state, action.input.id);
5441
+ targetOp.errors.push({
5302
5442
  id: action.input.id,
5303
5443
  name: action.input.errorName || "",
5304
5444
  code: action.input.errorCode || "",
@@ -5307,54 +5447,58 @@ const documentModelOperationErrorReducer = {
5307
5447
  });
5308
5448
  },
5309
5449
  setOperationErrorCodeOperation(state, action) {
5310
- const latestSpec = state.specifications[state.specifications.length - 1];
5311
- for (let i = 0; i < latestSpec.modules.length; i++) for (let j = 0; j < latestSpec.modules[i].operations.length; j++) for (let k = 0; k < latestSpec.modules[i].operations[j].errors.length; k++) if (latestSpec.modules[i].operations[j].errors[k].id == action.input.id) latestSpec.modules[i].operations[j].errors[k].code = action.input.errorCode || "";
5450
+ const error = findOperationErrorOrThrow(state, action.input.id);
5451
+ error.code = action.input.errorCode || "";
5312
5452
  },
5313
5453
  setOperationErrorNameOperation(state, action) {
5314
- const latestSpec = state.specifications[state.specifications.length - 1];
5315
- for (let i = 0; i < latestSpec.modules.length; i++) for (let j = 0; j < latestSpec.modules[i].operations.length; j++) for (let k = 0; k < latestSpec.modules[i].operations[j].errors.length; k++) if (latestSpec.modules[i].operations[j].errors[k].id == action.input.id) latestSpec.modules[i].operations[j].errors[k].name = action.input.errorName || "";
5454
+ const error = findOperationErrorOrThrow(state, action.input.id);
5455
+ error.name = action.input.errorName || "";
5316
5456
  },
5317
5457
  setOperationErrorDescriptionOperation(state, action) {
5318
- const latestSpec = state.specifications[state.specifications.length - 1];
5319
- for (let i = 0; i < latestSpec.modules.length; i++) for (let j = 0; j < latestSpec.modules[i].operations.length; j++) for (let k = 0; k < latestSpec.modules[i].operations[j].errors.length; k++) if (latestSpec.modules[i].operations[j].errors[k].id == action.input.id) latestSpec.modules[i].operations[j].errors[k].description = action.input.errorDescription || "";
5458
+ const error = findOperationErrorOrThrow(state, action.input.id);
5459
+ error.description = action.input.errorDescription || "";
5320
5460
  },
5321
5461
  setOperationErrorTemplateOperation(state, action) {
5322
- const latestSpec = state.specifications[state.specifications.length - 1];
5323
- for (let i = 0; i < latestSpec.modules.length; i++) for (let j = 0; j < latestSpec.modules[i].operations.length; j++) for (let k = 0; k < latestSpec.modules[i].operations[j].errors.length; k++) if (latestSpec.modules[i].operations[j].errors[k].id == action.input.id) latestSpec.modules[i].operations[j].errors[k].template = action.input.errorTemplate || "";
5462
+ const error = findOperationErrorOrThrow(state, action.input.id);
5463
+ error.template = action.input.errorTemplate || "";
5324
5464
  },
5325
5465
  deleteOperationErrorOperation(state, action) {
5326
5466
  const latestSpec = state.specifications[state.specifications.length - 1];
5327
- for (let i = 0; i < latestSpec.modules.length; i++) for (let j = 0; j < latestSpec.modules[i].operations.length; j++) latestSpec.modules[i].operations[j].errors = latestSpec.modules[i].operations[j].errors.filter((e) => e.id != action.input.id);
5467
+ if (!latestSpec.modules.some((mod) => mod.operations.some((op) => op.errors.some((e) => e.id === action.input.id)))) throw new Error(`Operation error "${action.input.id}" not found in the latest specification`);
5468
+ for (const mod of latestSpec.modules) for (const op of mod.operations) op.errors = op.errors.filter((e) => e.id != action.input.id);
5328
5469
  },
5329
5470
  reorderOperationErrorsOperation(state, action) {
5330
- const latestSpec = state.specifications[state.specifications.length - 1];
5331
- for (let i = 0; i < latestSpec.modules.length; i++) for (let j = 0; j < latestSpec.modules[i].operations.length; j++) if (latestSpec.modules[i].operations[j].id == action.input.operationId) latestSpec.modules[i].operations[j].errors.sort(sorter(action.input.order));
5471
+ const targetOp = findOperationOrThrow(state, action.input.operationId);
5472
+ targetOp.errors = orderBy(targetOp.errors, action.input.order);
5332
5473
  }
5333
5474
  };
5334
5475
  const documentModelOperationExampleReducer = {
5335
5476
  addOperationExampleOperation(state, action) {
5336
- const latestSpec = state.specifications[state.specifications.length - 1];
5337
- for (let i = 0; i < latestSpec.modules.length; i++) for (let j = 0; j < latestSpec.modules[i].operations.length; j++) if (latestSpec.modules[i].operations[j].id == action.input.operationId) latestSpec.modules[i].operations[j].examples.push({
5477
+ const targetOp = findOperationOrThrow(state, action.input.operationId);
5478
+ assertOperationExampleIdUnique(state, action.input.id);
5479
+ targetOp.examples.push({
5338
5480
  id: action.input.id,
5339
5481
  value: action.input.example
5340
5482
  });
5341
5483
  },
5342
5484
  updateOperationExampleOperation(state, action) {
5343
- const latestSpec = state.specifications[state.specifications.length - 1];
5344
- for (let i = 0; i < latestSpec.modules.length; i++) for (let j = 0; j < latestSpec.modules[i].operations.length; j++) for (let k = 0; k < latestSpec.modules[i].operations[j].examples.length; k++) if (latestSpec.modules[i].operations[j].examples[k].id == action.input.id) latestSpec.modules[i].operations[j].examples[k].value = action.input.example;
5485
+ const example = findOperationExampleOrThrow(state, action.input.id);
5486
+ example.value = action.input.example;
5345
5487
  },
5346
5488
  deleteOperationExampleOperation(state, action) {
5347
5489
  const latestSpec = state.specifications[state.specifications.length - 1];
5348
- for (let i = 0; i < latestSpec.modules.length; i++) for (let j = 0; j < latestSpec.modules[i].operations.length; j++) latestSpec.modules[i].operations[j].examples = latestSpec.modules[i].operations[j].examples.filter((e) => e.id != action.input.id);
5490
+ if (!latestSpec.modules.some((mod) => mod.operations.some((op) => op.examples.some((e) => e.id === action.input.id)))) throw new Error(`Operation example "${action.input.id}" not found in the latest specification`);
5491
+ for (const mod of latestSpec.modules) for (const op of mod.operations) op.examples = op.examples.filter((e) => e.id != action.input.id);
5349
5492
  },
5350
5493
  reorderOperationExamplesOperation(state, action) {
5351
- const latestSpec = state.specifications[state.specifications.length - 1];
5352
- for (let i = 0; i < latestSpec.modules.length; i++) for (let j = 0; j < latestSpec.modules[i].operations.length; j++) if (latestSpec.modules[i].operations[j].id == action.input.operationId) latestSpec.modules[i].operations[j].examples.sort(sorter(action.input.order));
5494
+ const targetOp = findOperationOrThrow(state, action.input.operationId);
5495
+ targetOp.examples = orderBy(targetOp.examples, action.input.order);
5353
5496
  }
5354
5497
  };
5355
5498
  const documentModelOperationReducer = {
5356
5499
  addOperationOperation(state, action) {
5357
5500
  validateOperationName(action.input.name, state);
5501
+ assertOperationIdUnique(state, action.input.id);
5358
5502
  findModuleOrThrow(state, action.input.moduleId).operations.push({
5359
5503
  id: action.input.id,
5360
5504
  name: action.input.name,
@@ -5369,8 +5513,8 @@ const documentModelOperationReducer = {
5369
5513
  },
5370
5514
  setOperationNameOperation(state, action) {
5371
5515
  if (action.input.name) validateOperationName(action.input.name, state, action.input.id);
5372
- const latestSpec = state.specifications[state.specifications.length - 1];
5373
- for (let i = 0; i < latestSpec.modules.length; i++) for (let j = 0; j < latestSpec.modules[i].operations.length; j++) if (latestSpec.modules[i].operations[j].id == action.input.id) latestSpec.modules[i].operations[j].name = action.input.name || "";
5516
+ const targetOp = findOperationOrThrow(state, action.input.id);
5517
+ targetOp.name = action.input.name || "";
5374
5518
  },
5375
5519
  setOperationScopeOperation(state, action) {
5376
5520
  const targetOp = findOperationOrThrow(state, action.input.id);
@@ -5380,40 +5524,39 @@ const documentModelOperationReducer = {
5380
5524
  targetOp.scope = action.input.scope || "global";
5381
5525
  },
5382
5526
  setOperationSchemaOperation(state, action) {
5383
- const latestSpec = state.specifications[state.specifications.length - 1];
5384
- for (let i = 0; i < latestSpec.modules.length; i++) for (let j = 0; j < latestSpec.modules[i].operations.length; j++) if (latestSpec.modules[i].operations[j].id == action.input.id) latestSpec.modules[i].operations[j].schema = action.input.schema || "";
5527
+ const targetOp = findOperationOrThrow(state, action.input.id);
5528
+ targetOp.schema = action.input.schema || "";
5385
5529
  },
5386
5530
  setOperationDescriptionOperation(state, action) {
5387
- const latestSpec = state.specifications[state.specifications.length - 1];
5388
- for (let i = 0; i < latestSpec.modules.length; i++) for (let j = 0; j < latestSpec.modules[i].operations.length; j++) if (latestSpec.modules[i].operations[j].id == action.input.id) latestSpec.modules[i].operations[j].description = action.input.description || "";
5531
+ const targetOp = findOperationOrThrow(state, action.input.id);
5532
+ targetOp.description = action.input.description || "";
5389
5533
  },
5390
5534
  setOperationTemplateOperation(state, action) {
5391
- const latestSpec = state.specifications[state.specifications.length - 1];
5392
- for (let i = 0; i < latestSpec.modules.length; i++) for (let j = 0; j < latestSpec.modules[i].operations.length; j++) if (latestSpec.modules[i].operations[j].id == action.input.id) latestSpec.modules[i].operations[j].template = action.input.template || "";
5535
+ const targetOp = findOperationOrThrow(state, action.input.id);
5536
+ targetOp.template = action.input.template || "";
5393
5537
  },
5394
5538
  setOperationReducerOperation(state, action) {
5395
- const latestSpec = state.specifications[state.specifications.length - 1];
5396
- for (let i = 0; i < latestSpec.modules.length; i++) for (let j = 0; j < latestSpec.modules[i].operations.length; j++) if (latestSpec.modules[i].operations[j].id == action.input.id) latestSpec.modules[i].operations[j].reducer = action.input.reducer || "";
5539
+ const targetOp = findOperationOrThrow(state, action.input.id);
5540
+ targetOp.reducer = action.input.reducer || "";
5397
5541
  },
5398
5542
  moveOperationOperation(state, action) {
5399
- const moveOperations = [];
5543
+ const targetModule = findModuleOrThrow(state, action.input.newModuleId);
5400
5544
  const latestSpec = state.specifications[state.specifications.length - 1];
5401
- for (let i = 0; i < latestSpec.modules.length; i++) latestSpec.modules[i].operations = latestSpec.modules[i].operations.filter((operation) => {
5402
- if (operation.id == action.input.operationId) {
5403
- moveOperations.push(operation);
5404
- return false;
5405
- }
5406
- return true;
5407
- });
5408
- for (let i = 0; i < latestSpec.modules.length; i++) if (latestSpec.modules[i].id == action.input.newModuleId) latestSpec.modules[i].operations.push(...moveOperations);
5545
+ const matches = latestSpec.modules.flatMap((mod) => mod.operations.filter((op) => op.id === action.input.operationId));
5546
+ if (matches.length === 0) throw new Error(`Operation "${action.input.operationId}" not found in the latest specification`);
5547
+ if (matches.length > 1) throw new Error(`Operation "${action.input.operationId}" is duplicated in the latest specification`);
5548
+ const moved = matches[0];
5549
+ for (const mod of latestSpec.modules) mod.operations = mod.operations.filter((op) => op.id !== action.input.operationId);
5550
+ targetModule.operations.push(moved);
5409
5551
  },
5410
5552
  deleteOperationOperation(state, action) {
5553
+ findOperationOrThrow(state, action.input.id);
5411
5554
  const latestSpec = state.specifications[state.specifications.length - 1];
5412
- for (let i = 0; i < latestSpec.modules.length; i++) latestSpec.modules[i].operations = latestSpec.modules[i].operations.filter((operation) => operation.id != action.input.id);
5555
+ for (const mod of latestSpec.modules) mod.operations = mod.operations.filter((operation) => operation.id != action.input.id);
5413
5556
  },
5414
5557
  reorderModuleOperationsOperation(state, action) {
5415
- const latestSpec = state.specifications[state.specifications.length - 1];
5416
- for (let i = 0; i < latestSpec.modules.length; i++) if (latestSpec.modules[i].id == action.input.moduleId) latestSpec.modules[i].operations.sort(sorter(action.input.order));
5558
+ const targetModule = findModuleOrThrow(state, action.input.moduleId);
5559
+ targetModule.operations = orderBy(targetModule.operations, action.input.order);
5417
5560
  }
5418
5561
  };
5419
5562
  const documentModelStateSchemaReducer = {
@@ -5438,18 +5581,22 @@ const documentModelStateSchemaReducer = {
5438
5581
  updateStateExampleOperation(state, action) {
5439
5582
  const latestSpec = state.specifications[state.specifications.length - 1];
5440
5583
  if (!Object.keys(latestSpec.state).includes(action.input.scope)) throw new Error(`Invalid scope: ${action.input.scope}`);
5441
- const examples = latestSpec.state[action.input.scope].examples;
5442
- for (let i = 0; i < examples.length; i++) if (examples[i].id == action.input.id) examples[i].value = action.input.newExample;
5584
+ const example = latestSpec.state[action.input.scope].examples.find((e) => e.id == action.input.id);
5585
+ if (!example) throw new Error(`State example "${action.input.id}" not found in scope "${action.input.scope}"`);
5586
+ example.value = action.input.newExample;
5443
5587
  },
5444
5588
  deleteStateExampleOperation(state, action) {
5445
5589
  const latestSpec = state.specifications[state.specifications.length - 1];
5446
- if (Object.keys(latestSpec.state).includes(action.input.scope)) latestSpec.state[action.input.scope].examples = latestSpec.state[action.input.scope].examples.filter((e) => e.id != action.input.id);
5447
- else throw new Error(`Invalid scope: ${action.input.scope}`);
5590
+ if (!Object.keys(latestSpec.state).includes(action.input.scope)) throw new Error(`Invalid scope: ${action.input.scope}`);
5591
+ const scopeState = latestSpec.state[action.input.scope];
5592
+ if (!scopeState.examples.some((e) => e.id == action.input.id)) throw new Error(`State example "${action.input.id}" not found in scope "${action.input.scope}"`);
5593
+ scopeState.examples = scopeState.examples.filter((e) => e.id != action.input.id);
5448
5594
  },
5449
5595
  reorderStateExamplesOperation(state, action) {
5450
5596
  const latestSpec = state.specifications[state.specifications.length - 1];
5451
- if (Object.keys(latestSpec.state).includes(action.input.scope)) latestSpec.state[action.input.scope].examples.sort(sorter(action.input.order));
5452
- else throw new Error(`Invalid scope: ${action.input.scope}`);
5597
+ if (!Object.keys(latestSpec.state).includes(action.input.scope)) throw new Error(`Invalid scope: ${action.input.scope}`);
5598
+ const scopeState = latestSpec.state[action.input.scope];
5599
+ scopeState.examples = orderBy(scopeState.examples, action.input.order);
5453
5600
  }
5454
5601
  };
5455
5602
  const documentModelVersioningReducer = {
@@ -5848,6 +5995,211 @@ function createState(baseState, globalState, localState) {
5848
5995
  };
5849
5996
  }
5850
5997
  //#endregion
5998
+ //#region ../document-model/dist/index.js
5999
+ const isStateOfType$1 = (state) => {
6000
+ return isDocumentModelState(state);
6001
+ };
6002
+ const assertIsStateOfType$1 = (state) => {
6003
+ assertIsDocumentModelState(state);
6004
+ };
6005
+ const isDocumentOfType$1 = (document) => {
6006
+ return isDocumentModelDocument(document);
6007
+ };
6008
+ const assertIsDocumentOfType$1 = (document) => {
6009
+ assertIsDocumentModelDocument(document);
6010
+ };
6011
+ const documentModelCreateState = (state) => {
6012
+ return {
6013
+ ...defaultBaseState(),
6014
+ global: {
6015
+ ...documentModelInitialGlobalState,
6016
+ ...state?.global ?? {}
6017
+ },
6018
+ local: {
6019
+ ...documentModelInitialLocalState,
6020
+ ...state?.local ?? {}
6021
+ }
6022
+ };
6023
+ };
6024
+ function documentModelCreateDocument(state) {
6025
+ return baseCreateDocument(documentModelCreateState, state, documentModelDocumentType);
6026
+ }
6027
+ const utils = {
6028
+ fileExtension: documentModelFileExtension,
6029
+ createState: documentModelCreateState,
6030
+ createDocument: documentModelCreateDocument,
6031
+ loadFromInput: documentModelLoadFromInput,
6032
+ saveToFileHandle: documentModelSaveToFileHandle,
6033
+ isStateOfType: isStateOfType$1,
6034
+ assertIsStateOfType: assertIsStateOfType$1,
6035
+ isDocumentOfType: isDocumentOfType$1,
6036
+ assertIsDocumentOfType: assertIsDocumentOfType$1
6037
+ };
6038
+ const documentModelDocumentModelModule = {
6039
+ reducer: documentModelReducer,
6040
+ documentModel: createState(defaultBaseState(), documentModelGlobalState),
6041
+ actions,
6042
+ utils
6043
+ };
6044
+ (class PHDocumentController {
6045
+ module;
6046
+ _document;
6047
+ listeners = [];
6048
+ constructor(module, initialDocument) {
6049
+ this.module = module;
6050
+ this._document = initialDocument ?? module.utils.createDocument();
6051
+ for (const actionType in this.module.actions) Object.defineProperty(this, actionType, { value: (input) => {
6052
+ const action = this.module.actions[actionType](input);
6053
+ this._document = this.module.reducer(this._document, action);
6054
+ this.notifyListeners();
6055
+ return this;
6056
+ } });
6057
+ }
6058
+ get document() {
6059
+ return this._document;
6060
+ }
6061
+ get header() {
6062
+ return this.document.header;
6063
+ }
6064
+ get state() {
6065
+ return this.document.state;
6066
+ }
6067
+ get initialState() {
6068
+ return this.document.initialState;
6069
+ }
6070
+ get operations() {
6071
+ return this.document.operations;
6072
+ }
6073
+ get clipboard() {
6074
+ return this.document.clipboard;
6075
+ }
6076
+ onChange(listener) {
6077
+ this.listeners.push(listener);
6078
+ return () => {
6079
+ this.listeners = this.listeners.filter((l) => l !== listener);
6080
+ };
6081
+ }
6082
+ notifyListeners() {
6083
+ if (this.listeners.length === 0) return;
6084
+ const event = { document: this._document };
6085
+ for (const listener of this.listeners) listener(event);
6086
+ }
6087
+ static forDocumentModel(module) {
6088
+ return class extends PHDocumentController {
6089
+ constructor(initialDocument) {
6090
+ super(module, initialDocument);
6091
+ }
6092
+ };
6093
+ }
6094
+ }).forDocumentModel(documentModelDocumentModelModule);
6095
+ const tokenSub = /@([a-zA-Z0-9_]+)/g;
6096
+ const dtf = new Intl.DateTimeFormat(void 0, {
6097
+ hour12: false,
6098
+ hour: "2-digit",
6099
+ minute: "2-digit",
6100
+ second: "2-digit",
6101
+ fractionalSecondDigits: 2
6102
+ });
6103
+ const stringify = (value, includeStack) => {
6104
+ if (value === null || value === void 0) return "null";
6105
+ if (typeof value === "string") return value;
6106
+ if (value instanceof Error) {
6107
+ const base = `${value.name}: ${value.message}`;
6108
+ return includeStack && value.stack ? `${base}\n${value.stack}` : base;
6109
+ }
6110
+ if (typeof value === "object") try {
6111
+ return JSON.stringify(value);
6112
+ } catch {
6113
+ return Object.prototype.toString.call(value);
6114
+ }
6115
+ if (typeof value === "function") {
6116
+ const name = value.name;
6117
+ return name ? `${name}()` : "anonymous()";
6118
+ }
6119
+ return String(value);
6120
+ };
6121
+ const formatMessage = (tagString, message, replacements, includeStack) => {
6122
+ const meta = {};
6123
+ const uniqueTokens = [];
6124
+ let results;
6125
+ while ((results = tokenSub.exec(message)) !== null) {
6126
+ const tokenName = results[1];
6127
+ if (uniqueTokens.indexOf(tokenName) === -1) {
6128
+ uniqueTokens.push(tokenName);
6129
+ meta[tokenName] = replacements[uniqueTokens.length - 1];
6130
+ }
6131
+ }
6132
+ for (const [key, value] of Object.entries(meta)) message = message.replaceAll(`@${key}`, stringify(value, includeStack));
6133
+ const extras = replacements.slice(uniqueTokens.length);
6134
+ if (extras.length > 0) message = `${message} ${extras.map((v) => stringify(v, includeStack)).join(" ")}`;
6135
+ if (tagString.length > 0) message = `${tagString} ${message}`;
6136
+ const now = /* @__PURE__ */ new Date();
6137
+ meta["timestamp"] = dtf.format(now);
6138
+ return [message, meta];
6139
+ };
6140
+ const LOG_LEVELS = {
6141
+ verbose: 0,
6142
+ debug: 1,
6143
+ info: 2,
6144
+ warn: 3,
6145
+ error: 4
6146
+ };
6147
+ const logger = new class ConsoleLogger {
6148
+ #tags;
6149
+ #tagString;
6150
+ #level = LOG_LEVELS.info;
6151
+ errorHandler;
6152
+ constructor(tags, handler) {
6153
+ this.#tags = tags || [];
6154
+ this.#tagString = this.#tags.map((tag) => `[${tag}]`).join("");
6155
+ this.errorHandler = handler ?? (() => {});
6156
+ }
6157
+ get level() {
6158
+ return Object.keys(LOG_LEVELS).find((key) => LOG_LEVELS[key] === this.#level);
6159
+ }
6160
+ set level(value) {
6161
+ this.#level = LOG_LEVELS[value];
6162
+ }
6163
+ child(tags) {
6164
+ const logger = new ConsoleLogger([...this.#tags, ...tags], this.errorHandler);
6165
+ logger.level = this.level;
6166
+ return logger;
6167
+ }
6168
+ get #includeStack() {
6169
+ return this.#level <= LOG_LEVELS.debug;
6170
+ }
6171
+ verbose(message, ...replacements) {
6172
+ if (this.#level <= LOG_LEVELS.verbose) {
6173
+ const [formattedMessage, meta] = formatMessage(this.#tagString, message, replacements, this.#includeStack);
6174
+ console.debug(`[${meta["timestamp"]}] ${formattedMessage}`);
6175
+ }
6176
+ }
6177
+ debug(message, ...replacements) {
6178
+ if (this.#level <= LOG_LEVELS.debug) {
6179
+ const [formattedMessage, meta] = formatMessage(this.#tagString, message, replacements, this.#includeStack);
6180
+ console.debug(`[${meta["timestamp"]}] ${formattedMessage}`);
6181
+ }
6182
+ }
6183
+ info(message, ...replacements) {
6184
+ if (this.#level <= LOG_LEVELS.info) {
6185
+ const [formattedMessage, meta] = formatMessage(this.#tagString, message, replacements, this.#includeStack);
6186
+ console.info(`[${meta["timestamp"]}] ${formattedMessage}`);
6187
+ }
6188
+ }
6189
+ warn(message, ...replacements) {
6190
+ if (this.#level <= LOG_LEVELS.warn) {
6191
+ const [formattedMessage, meta] = formatMessage(this.#tagString, message, replacements, this.#includeStack);
6192
+ console.warn(`[${meta["timestamp"]}] ${formattedMessage}`);
6193
+ }
6194
+ }
6195
+ error(message, ...replacements) {
6196
+ if (this.#level <= LOG_LEVELS.error) {
6197
+ const [formattedMessage, meta] = formatMessage(this.#tagString, message, replacements, this.#includeStack);
6198
+ console.error(`[${meta["timestamp"]}] ${formattedMessage}`);
6199
+ }
6200
+ }
6201
+ }();
6202
+ //#endregion
5851
6203
  //#region ../shared/dist/document-drive/index.js
5852
6204
  var __defProp = Object.defineProperty;
5853
6205
  var __exportAll = (all, no_symbols) => {
@@ -6453,12 +6805,12 @@ function handleTargetNameCollisions(params) {
6453
6805
  return targetNodeChildrenNames.includes(srcName) ? `${srcName} (copy) ${getNextCopyNumber(targetNodeChildrenNames, srcName)}` : srcName;
6454
6806
  }
6455
6807
  const isValidName = (name) => {
6456
- return /^[a-zA-Z0-9-_.\s()]+$/.test(name);
6808
+ return name.trim().length > 0 && !/[\u0000-\u001F\u007F]/.test(name);
6457
6809
  };
6458
6810
  const nodeReducer = {
6459
6811
  addFileOperation(state, action, dispatch) {
6460
6812
  if (state.nodes.find((node) => node.id === action.input.id)) throw new Error(`Node with id ${action.input.id} already exists!`);
6461
- if (!isValidName(action.input.name)) throw new Error(`Invalid name: '${action.input.name}'. Names must be valid URL characters.`);
6813
+ if (!isValidName(action.input.name)) throw new Error(`Invalid name: '${action.input.name}'. Names must not be empty or contain control characters.`);
6462
6814
  const name = handleTargetNameCollisions({
6463
6815
  nodes: state.nodes,
6464
6816
  srcName: action.input.name,
@@ -6484,7 +6836,7 @@ const nodeReducer = {
6484
6836
  },
6485
6837
  addFolderOperation(state, action) {
6486
6838
  if (state.nodes.find((node) => node.id === action.input.id)) throw new Error(`Node with id ${action.input.id} already exists!`);
6487
- if (!isValidName(action.input.name)) throw new Error(`Invalid name: '${action.input.name}'. Names must be valid URL characters.`);
6839
+ if (!isValidName(action.input.name)) throw new Error(`Invalid name: '${action.input.name}'. Names must not be empty or contain control characters.`);
6488
6840
  const name = handleTargetNameCollisions({
6489
6841
  nodes: state.nodes,
6490
6842
  srcName: action.input.name,
@@ -6512,7 +6864,7 @@ const nodeReducer = {
6512
6864
  });
6513
6865
  },
6514
6866
  updateFileOperation(state, action) {
6515
- if (action.input.name && !isValidName(action.input.name)) throw new Error(`Invalid name: '${action.input.name}'. Names must be valid URL characters.`);
6867
+ if (action.input.name && !isValidName(action.input.name)) throw new Error(`Invalid name: '${action.input.name}'. Names must not be empty or contain control characters.`);
6516
6868
  state.nodes = state.nodes.map((node) => node.id === action.input.id ? {
6517
6869
  ...node,
6518
6870
  name: handleTargetNameCollisions({
@@ -6526,7 +6878,7 @@ const nodeReducer = {
6526
6878
  state.nodes.sort((a, b) => a.id.localeCompare(b.id));
6527
6879
  },
6528
6880
  updateNodeOperation(state, action) {
6529
- if (action.input.name && !isValidName(action.input.name)) throw new Error(`Invalid name: '${action.input.name}'. Names must be valid URL characters.`);
6881
+ if (action.input.name && !isValidName(action.input.name)) throw new Error(`Invalid name: '${action.input.name}'. Names must not be empty or contain control characters.`);
6530
6882
  state.nodes = state.nodes.map((node) => node.id === action.input.id ? {
6531
6883
  ...node,
6532
6884
  name: handleTargetNameCollisions({
@@ -6683,10 +7035,7 @@ const driveCreateState = (state) => {
6683
7035
  };
6684
7036
  };
6685
7037
  const driveCreateDocument = (state) => {
6686
- const document = baseCreateDocument(driveCreateState, state);
6687
- document.header.documentType = driveDocumentType;
6688
- document.header.id = generateId();
6689
- return document;
7038
+ return baseCreateDocument(driveCreateState, state, driveDocumentType);
6690
7039
  };
6691
7040
  const driveSaveToFileHandle = (document, input) => {
6692
7041
  return baseSaveToFileHandle(document, input);
@@ -6694,16 +7043,16 @@ const driveSaveToFileHandle = (document, input) => {
6694
7043
  const driveLoadFromInput = (input) => {
6695
7044
  return baseLoadFromInput(input, driveDocumentReducer);
6696
7045
  };
6697
- const isStateOfType$1 = (state) => {
7046
+ const isStateOfType = (state) => {
6698
7047
  return isDriveState(state);
6699
7048
  };
6700
- const assertIsStateOfType$1 = (state) => {
7049
+ const assertIsStateOfType = (state) => {
6701
7050
  assertIsDriveState(state);
6702
7051
  };
6703
- const isDocumentOfType$1 = (document) => {
7052
+ const isDocumentOfType = (document) => {
6704
7053
  return isDriveDocument(document);
6705
7054
  };
6706
- const assertIsDocumentOfType$1 = (document) => {
7055
+ const assertIsDocumentOfType = (document) => {
6707
7056
  assertIsDriveDocument(document);
6708
7057
  };
6709
7058
  const driveDocumentModelModule = {
@@ -6716,220 +7065,13 @@ const driveDocumentModelModule = {
6716
7065
  createDocument: driveCreateDocument,
6717
7066
  loadFromInput: driveLoadFromInput,
6718
7067
  saveToFileHandle: driveSaveToFileHandle,
6719
- isStateOfType: isStateOfType$1,
6720
- assertIsStateOfType: assertIsStateOfType$1,
6721
- isDocumentOfType: isDocumentOfType$1,
6722
- assertIsDocumentOfType: assertIsDocumentOfType$1
7068
+ isStateOfType,
7069
+ assertIsStateOfType,
7070
+ isDocumentOfType,
7071
+ assertIsDocumentOfType
6723
7072
  }
6724
7073
  };
6725
7074
  //#endregion
6726
- //#region ../document-model/dist/index.js
6727
- const isStateOfType = (state) => {
6728
- return isDocumentModelState(state);
6729
- };
6730
- const assertIsStateOfType = (state) => {
6731
- assertIsDocumentModelState(state);
6732
- };
6733
- const isDocumentOfType = (document) => {
6734
- return isDocumentModelDocument(document);
6735
- };
6736
- const assertIsDocumentOfType = (document) => {
6737
- assertIsDocumentModelDocument(document);
6738
- };
6739
- const documentModelCreateState = (state) => {
6740
- return {
6741
- ...defaultBaseState(),
6742
- global: {
6743
- ...documentModelInitialGlobalState,
6744
- ...state?.global ?? {}
6745
- },
6746
- local: {
6747
- ...documentModelInitialLocalState,
6748
- ...state?.local ?? {}
6749
- }
6750
- };
6751
- };
6752
- function documentModelCreateDocument(state) {
6753
- const document = baseCreateDocument(documentModelCreateState, state);
6754
- document.header.documentType = documentModelDocumentType;
6755
- return document;
6756
- }
6757
- const utils = {
6758
- fileExtension: documentModelFileExtension,
6759
- createState: documentModelCreateState,
6760
- createDocument: documentModelCreateDocument,
6761
- loadFromInput: documentModelLoadFromInput,
6762
- saveToFileHandle: documentModelSaveToFileHandle,
6763
- isStateOfType,
6764
- assertIsStateOfType,
6765
- isDocumentOfType,
6766
- assertIsDocumentOfType
6767
- };
6768
- const documentModelDocumentModelModule = {
6769
- reducer: documentModelReducer,
6770
- documentModel: createState(defaultBaseState(), documentModelGlobalState),
6771
- actions,
6772
- utils
6773
- };
6774
- (class PHDocumentController {
6775
- module;
6776
- _document;
6777
- listeners = [];
6778
- constructor(module, initialDocument) {
6779
- this.module = module;
6780
- this._document = initialDocument ?? module.utils.createDocument();
6781
- for (const actionType in this.module.actions) Object.defineProperty(this, actionType, { value: (input) => {
6782
- const action = this.module.actions[actionType](input);
6783
- this._document = this.module.reducer(this._document, action);
6784
- this.notifyListeners();
6785
- return this;
6786
- } });
6787
- }
6788
- get document() {
6789
- return this._document;
6790
- }
6791
- get header() {
6792
- return this.document.header;
6793
- }
6794
- get state() {
6795
- return this.document.state;
6796
- }
6797
- get initialState() {
6798
- return this.document.initialState;
6799
- }
6800
- get operations() {
6801
- return this.document.operations;
6802
- }
6803
- get clipboard() {
6804
- return this.document.clipboard;
6805
- }
6806
- onChange(listener) {
6807
- this.listeners.push(listener);
6808
- return () => {
6809
- this.listeners = this.listeners.filter((l) => l !== listener);
6810
- };
6811
- }
6812
- notifyListeners() {
6813
- if (this.listeners.length === 0) return;
6814
- const event = { document: this._document };
6815
- for (const listener of this.listeners) listener(event);
6816
- }
6817
- static forDocumentModel(module) {
6818
- return class extends PHDocumentController {
6819
- constructor(initialDocument) {
6820
- super(module, initialDocument);
6821
- }
6822
- };
6823
- }
6824
- }).forDocumentModel(documentModelDocumentModelModule);
6825
- const tokenSub = /@([a-zA-Z0-9_]+)/g;
6826
- const dtf = new Intl.DateTimeFormat(void 0, {
6827
- hour12: false,
6828
- hour: "2-digit",
6829
- minute: "2-digit",
6830
- second: "2-digit",
6831
- fractionalSecondDigits: 2
6832
- });
6833
- const stringify = (value, includeStack) => {
6834
- if (value === null || value === void 0) return "null";
6835
- if (typeof value === "string") return value;
6836
- if (value instanceof Error) {
6837
- const base = `${value.name}: ${value.message}`;
6838
- return includeStack && value.stack ? `${base}\n${value.stack}` : base;
6839
- }
6840
- if (typeof value === "object") try {
6841
- return JSON.stringify(value);
6842
- } catch {
6843
- return String(value);
6844
- }
6845
- if (typeof value === "function") {
6846
- const name = value.name;
6847
- return name ? `${name}()` : "anonymous()";
6848
- }
6849
- return String(value);
6850
- };
6851
- const formatMessage = (tagString, message, replacements, includeStack) => {
6852
- const meta = {};
6853
- const uniqueTokens = [];
6854
- let results;
6855
- while ((results = tokenSub.exec(message)) !== null) {
6856
- const tokenName = results[1];
6857
- if (uniqueTokens.indexOf(tokenName) === -1) {
6858
- uniqueTokens.push(tokenName);
6859
- meta[tokenName] = replacements[uniqueTokens.length - 1];
6860
- }
6861
- }
6862
- for (const [key, value] of Object.entries(meta)) message = message.replaceAll(`@${key}`, stringify(value, includeStack));
6863
- const extras = replacements.slice(uniqueTokens.length);
6864
- if (extras.length > 0) message = `${message} ${extras.map((v) => stringify(v, includeStack)).join(" ")}`;
6865
- if (tagString.length > 0) message = `${tagString} ${message}`;
6866
- const now = /* @__PURE__ */ new Date();
6867
- meta["timestamp"] = dtf.format(now);
6868
- return [message, meta];
6869
- };
6870
- const LOG_LEVELS = {
6871
- verbose: 0,
6872
- debug: 1,
6873
- info: 2,
6874
- warn: 3,
6875
- error: 4
6876
- };
6877
- const logger = new class ConsoleLogger {
6878
- #tags;
6879
- #tagString;
6880
- #level = LOG_LEVELS.info;
6881
- errorHandler;
6882
- constructor(tags, handler) {
6883
- this.#tags = tags || [];
6884
- this.#tagString = this.#tags.map((tag) => `[${tag}]`).join("");
6885
- this.errorHandler = handler ?? (() => {});
6886
- }
6887
- get level() {
6888
- return Object.keys(LOG_LEVELS).find((key) => LOG_LEVELS[key] === this.#level);
6889
- }
6890
- set level(value) {
6891
- this.#level = LOG_LEVELS[value];
6892
- }
6893
- child(tags) {
6894
- const logger = new ConsoleLogger([...this.#tags, ...tags], this.errorHandler);
6895
- logger.level = this.level;
6896
- return logger;
6897
- }
6898
- get #includeStack() {
6899
- return this.#level <= LOG_LEVELS.debug;
6900
- }
6901
- verbose(message, ...replacements) {
6902
- if (this.#level <= LOG_LEVELS.verbose) {
6903
- const [formattedMessage, meta] = formatMessage(this.#tagString, message, replacements, this.#includeStack);
6904
- console.debug(`[${meta["timestamp"]}] ${formattedMessage}`);
6905
- }
6906
- }
6907
- debug(message, ...replacements) {
6908
- if (this.#level <= LOG_LEVELS.debug) {
6909
- const [formattedMessage, meta] = formatMessage(this.#tagString, message, replacements, this.#includeStack);
6910
- console.debug(`[${meta["timestamp"]}] ${formattedMessage}`);
6911
- }
6912
- }
6913
- info(message, ...replacements) {
6914
- if (this.#level <= LOG_LEVELS.info) {
6915
- const [formattedMessage, meta] = formatMessage(this.#tagString, message, replacements, this.#includeStack);
6916
- console.info(`[${meta["timestamp"]}] ${formattedMessage}`);
6917
- }
6918
- }
6919
- warn(message, ...replacements) {
6920
- if (this.#level <= LOG_LEVELS.warn) {
6921
- const [formattedMessage, meta] = formatMessage(this.#tagString, message, replacements, this.#includeStack);
6922
- console.warn(`[${meta["timestamp"]}] ${formattedMessage}`);
6923
- }
6924
- }
6925
- error(message, ...replacements) {
6926
- if (this.#level <= LOG_LEVELS.error) {
6927
- const [formattedMessage, meta] = formatMessage(this.#tagString, message, replacements, this.#includeStack);
6928
- console.error(`[${meta["timestamp"]}] ${formattedMessage}`);
6929
- }
6930
- }
6931
- }();
6932
- //#endregion
6933
- export { replayDocument as A, setOperationDescription as B, defaultBaseState as C, documentModelDocumentType as D, deleteOperationError as E, setModelExtension as F, undo as G, setOperationName as H, setModelId as I, validateStateSchemaName as J, validateInitialState as K, setModelName as L, setAuthorWebsite as M, setInitialState as N, isDocumentAction as O, setModelDescription as P, setModuleName as R, createZip as S, deleteOperation as T, setOperationSchema as U, setOperationErrorName as V, setStateSchema as W, generateId as Y, baseSaveToFileHandle as _, driveDocumentModelModule as a, createReducer as b, isFileNode as c, updateNode as d, addModule as f, baseLoadFromInput as g, baseCreateDocument as h, copyNode as i, setAuthorName as j, redo as k, isFolderNode as l, addOperationError as m, logger as n, generateNodesCopy as o, addOperation as p, validateModules as q, addFolder as r, handleTargetNameCollisions as s, documentModelDocumentModelModule as t, moveNode as u, buildSignedAction as v, deleteModule as w, createState as x, createPresignedHeader as y, setName as z };
7075
+ export { replayDocument as A, setOperationDescription as B, defaultBaseState as C, documentModelDocumentType as D, deleteOperationError as E, setModelExtension as F, undo as G, setOperationName as H, setModelId as I, validateStateSchemaName as J, validateInitialState as K, setModelName as L, setAuthorWebsite as M, setInitialState as N, isDocumentAction as O, setModelDescription as P, setModuleName as R, createZip as S, deleteOperation as T, setOperationSchema as U, setOperationErrorName as V, setStateSchema as W, generateId as Y, baseSaveToFileHandle as _, handleTargetNameCollisions as a, createReducer as b, moveNode as c, logger as d, addModule as f, baseLoadFromInput as g, baseCreateDocument as h, generateNodesCopy as i, setAuthorName as j, redo as k, updateNode as l, addOperationError as m, copyNode as n, isFileNode as o, addOperation as p, validateModules as q, driveDocumentModelModule as r, isFolderNode as s, addFolder as t, documentModelDocumentModelModule as u, buildSignedAction as v, deleteModule as w, createState as x, createPresignedHeader as y, setName as z };
6934
7076
 
6935
- //# sourceMappingURL=dist-Bz4SgEHs.mjs.map
7077
+ //# sourceMappingURL=document-drive-sM33juXr.mjs.map