@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 { 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, w as __toESM, x as __commonJSMin } from "./schemas-Bqem6NRm.js";
2
- import { r as pascalCase } from "./dist-BXygvBtd.js";
1
+ import { E as __commonJSMin, _ as string, c as any, f as lazy, h as object, k 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-CXoKspdx.js";
3
2
  //#endregion
4
3
  //#region ../../node_modules/.pnpm/safe-stable-stringify@2.5.0/node_modules/safe-stable-stringify/esm/wrapper.js
5
4
  var import_safe_stable_stringify = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exports, module) => {
@@ -590,7 +589,7 @@ function isBE() {
590
589
  return new Uint8Array(new Uint16Array([65279]).buffer)[0] === 254;
591
590
  }
592
591
  //#endregion
593
- //#region ../shared/dist/utils-bCWnsmtD.js
592
+ //#region ../shared/dist/utils-DKOFCM0Q.js
594
593
  const hashBrowser = (data, algorithm = "sha1", encoding = "base64", _params) => {
595
594
  if (!["sha1"].includes(algorithm)) throw new Error(`Hashing algorithm not supported: "${algorithm}". Available: sha1`);
596
595
  if (!["base64", "hex"].includes(encoding)) throw new Error(`Hash encoding not supported: "${encoding}". Available: base64, hex`);
@@ -4368,16 +4367,72 @@ function isDocumentAction(action) {
4368
4367
  ].includes(action.type);
4369
4368
  }
4370
4369
  /**
4371
- * Important note: it is the responsibility of the caller to set the document type
4372
- * on the header.
4370
+ * The document-scope operations a reactor mints on `create`, so a standalone
4371
+ * document carries its initial state when exported outside a reactor.
4373
4372
  */
4374
- function baseCreateDocument(createState, initialState) {
4373
+ function createDocumentScopeOperations(header, state) {
4374
+ const createInput = {
4375
+ model: header.documentType,
4376
+ version: 0,
4377
+ documentId: header.id,
4378
+ signing: {
4379
+ signature: header.id,
4380
+ publicKey: header.sig.publicKey,
4381
+ nonce: header.sig.nonce,
4382
+ createdAtUtcIso: header.createdAtUtcIso,
4383
+ documentType: header.documentType
4384
+ },
4385
+ slug: header.slug,
4386
+ name: header.name,
4387
+ branch: header.branch,
4388
+ meta: header.meta,
4389
+ protocolVersions: header.protocolVersions ?? { "base-reducer": 2 }
4390
+ };
4391
+ const upgradeInput = {
4392
+ model: header.documentType,
4393
+ fromVersion: 0,
4394
+ toVersion: state.document.version,
4395
+ documentId: header.id,
4396
+ initialState: state
4397
+ };
4398
+ return [{
4399
+ id: generateId(),
4400
+ type: "CREATE_DOCUMENT",
4401
+ scope: "document",
4402
+ timestampUtcMs: header.createdAtUtcIso,
4403
+ input: createInput
4404
+ }, {
4405
+ id: generateId(),
4406
+ type: "UPGRADE_DOCUMENT",
4407
+ scope: "document",
4408
+ timestampUtcMs: header.createdAtUtcIso,
4409
+ input: upgradeInput
4410
+ }].map((action, index) => ({
4411
+ ...action,
4412
+ action,
4413
+ id: deriveOperationId(header.id, "document", header.branch, action.id),
4414
+ hash: "",
4415
+ error: void 0,
4416
+ index,
4417
+ skip: 0
4418
+ }));
4419
+ }
4420
+ /**
4421
+ * Creates a new document. When `documentType` is given the header is stamped
4422
+ * with it and the document-scope operations are seeded.
4423
+ */
4424
+ function baseCreateDocument(createState, initialState, documentType = "") {
4375
4425
  const state = createState(initialState);
4426
+ const header = createPresignedHeader(generateId(), documentType);
4376
4427
  return {
4377
- header: createPresignedHeader(),
4428
+ header,
4378
4429
  state,
4379
4430
  initialState: state,
4380
- operations: {
4431
+ operations: documentType ? {
4432
+ global: [],
4433
+ local: [],
4434
+ document: createDocumentScopeOperations(header, state)
4435
+ } : {
4381
4436
  global: [],
4382
4437
  local: []
4383
4438
  },
@@ -5075,6 +5130,15 @@ const RESERVED_OPERATION_NAMES = [
5075
5130
  "NOOP"
5076
5131
  ];
5077
5132
  /**
5133
+ * Operation names become the literal action `type` string at runtime and the
5134
+ * key for codegen's action union. They must be SCREAMING_SNAKE_CASE so the
5135
+ * generated TypeScript is valid.
5136
+ */
5137
+ const OPERATION_NAME_PATTERN = /^[A-Z][A-Z0-9_]*$/;
5138
+ function isValidOperationNameFormat(name) {
5139
+ return OPERATION_NAME_PATTERN.test(name);
5140
+ }
5141
+ /**
5078
5142
  * Check if name conflicts with base reducer actions (case-insensitive).
5079
5143
  */
5080
5144
  function isReservedOperationName(name) {
@@ -5104,6 +5168,11 @@ function getAllOperationNames(state, excludeOperationId) {
5104
5168
  */
5105
5169
  function validateOperationName(name, state, excludeOperationId) {
5106
5170
  if (!name) return;
5171
+ if (!isValidOperationNameFormat(name)) {
5172
+ const suggestion = constantCase(name);
5173
+ const hint = suggestion && suggestion !== name && isValidOperationNameFormat(suggestion) ? ` Did you mean "${suggestion}"?` : "";
5174
+ throw new Error(`Operation name "${name}" is invalid. Names must be SCREAMING_SNAKE_CASE (matching ${OPERATION_NAME_PATTERN.source}).${hint}`);
5175
+ }
5107
5176
  const upperName = name.toUpperCase();
5108
5177
  if (isReservedOperationName(name)) throw new Error(`Operation name "${name}" is reserved. Please use a different name.`);
5109
5178
  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.`);
@@ -5199,6 +5268,60 @@ function findOperationOrThrow(state, operationId) {
5199
5268
  }
5200
5269
  throw new Error(`Operation "${operationId}" not found in the latest specification`);
5201
5270
  }
5271
+ /**
5272
+ * Find an operation error by id across all operations in the latest
5273
+ * specification, or throw. Throws on a duplicate id too: setters act on a
5274
+ * single error, so an ambiguous id must fail loudly rather than mutate an
5275
+ * arbitrary match.
5276
+ */
5277
+ function findOperationErrorOrThrow(state, errorId) {
5278
+ const matches = state.specifications[state.specifications.length - 1]?.modules.flatMap((mod) => mod.operations.flatMap((op) => op.errors.filter((e) => e.id === errorId))) ?? [];
5279
+ if (matches.length === 0) throw new Error(`Operation error "${errorId}" not found in the latest specification`);
5280
+ if (matches.length > 1) throw new Error(`Operation error "${errorId}" is duplicated in the latest specification`);
5281
+ return matches[0];
5282
+ }
5283
+ /**
5284
+ * Find an operation example (code example) by id across all operations in the
5285
+ * latest specification, or throw. Throws on a duplicate id for the same reason
5286
+ * as findOperationErrorOrThrow.
5287
+ */
5288
+ function findOperationExampleOrThrow(state, exampleId) {
5289
+ const matches = state.specifications[state.specifications.length - 1]?.modules.flatMap((mod) => mod.operations.flatMap((op) => op.examples.filter((e) => e.id === exampleId))) ?? [];
5290
+ if (matches.length === 0) throw new Error(`Operation example "${exampleId}" not found in the latest specification`);
5291
+ if (matches.length > 1) throw new Error(`Operation example "${exampleId}" is duplicated in the latest specification`);
5292
+ return matches[0];
5293
+ }
5294
+ /**
5295
+ * Assert no module in the latest specification already uses `id`. Modules are
5296
+ * targeted by id by the setter/delete/reorder reducers, so a duplicate id makes
5297
+ * those operations ambiguous.
5298
+ */
5299
+ function assertModuleIdUnique(state, id) {
5300
+ if (state.specifications[state.specifications.length - 1]?.modules.some((m) => m.id === id)) throw new Error(`Module "${id}" already exists in the latest specification`);
5301
+ }
5302
+ /**
5303
+ * Assert no operation in the latest specification already uses `id`. Operations
5304
+ * are targeted by id across all modules, so the id must be unique document-wide.
5305
+ */
5306
+ function assertOperationIdUnique(state, id) {
5307
+ 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`);
5308
+ }
5309
+ /**
5310
+ * Assert no operation error in the latest specification already uses `id`.
5311
+ * Error ids are targeted document-wide by the setter/delete reducers, so the id
5312
+ * must be unique to keep those operations unambiguous.
5313
+ */
5314
+ function assertOperationErrorIdUnique(state, id) {
5315
+ 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`);
5316
+ }
5317
+ /**
5318
+ * Assert no operation example in the latest specification already uses `id`.
5319
+ * Example ids are targeted document-wide by the update/delete reducers, so the
5320
+ * id must be unique to keep those operations unambiguous.
5321
+ */
5322
+ function assertOperationExampleIdUnique(state, id) {
5323
+ 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`);
5324
+ }
5202
5325
  function validateOperations(operations) {
5203
5326
  const errors = [];
5204
5327
  const scopes = Object.keys(operations);
@@ -5221,10 +5344,22 @@ function validateOperations(operations) {
5221
5344
  }
5222
5345
  return errors;
5223
5346
  }
5224
- function sorter(order) {
5225
- const mapping = {};
5226
- order.forEach((key, index) => mapping[key] = index);
5227
- return (a, b) => (mapping[b.id] || 999999) - (mapping[a.id] || 999999);
5347
+ /**
5348
+ * Reorder `items` by the position of their id in `order`. Ids not listed in
5349
+ * `order` keep their relative position after the listed ones. Throws if `order`
5350
+ * references an id that isn't present, so a stale or mistyped id fails loudly
5351
+ * instead of silently producing an arbitrary order.
5352
+ */
5353
+ function orderBy(items, order) {
5354
+ const ids = new Set(items.map((item) => item.id));
5355
+ for (const id of order) if (!ids.has(id)) throw new Error(`Cannot reorder: unknown id "${id}"`);
5356
+ const rank = new Map(order.map((id, index) => [id, index]));
5357
+ return items.map((item, index) => ({
5358
+ item,
5359
+ index
5360
+ })).sort((a, b) => {
5361
+ return (rank.get(a.item.id) ?? Number.MAX_SAFE_INTEGER) - (rank.get(b.item.id) ?? Number.MAX_SAFE_INTEGER) || a.index - b.index;
5362
+ }).map(({ item }) => item);
5228
5363
  }
5229
5364
  const documentModelHeaderReducer = {
5230
5365
  setModelNameOperation(state, action) {
@@ -5256,6 +5391,7 @@ const documentModelHeaderReducer = {
5256
5391
  };
5257
5392
  const documentModelModuleReducer = {
5258
5393
  addModuleOperation(state, action) {
5394
+ assertModuleIdUnique(state, action.input.id);
5259
5395
  state.specifications[state.specifications.length - 1].modules.push({
5260
5396
  id: action.input.id,
5261
5397
  name: action.input.name,
@@ -5264,24 +5400,28 @@ const documentModelModuleReducer = {
5264
5400
  });
5265
5401
  },
5266
5402
  setModuleNameOperation(state, action) {
5267
- const latestSpec = state.specifications[state.specifications.length - 1];
5268
- for (let i = 0; i < latestSpec.modules.length; i++) if (latestSpec.modules[i].id === action.input.id) latestSpec.modules[i].name = action.input.name || "";
5403
+ const targetModule = findModuleOrThrow(state, action.input.id);
5404
+ targetModule.name = action.input.name || "";
5269
5405
  },
5270
5406
  setModuleDescriptionOperation(state, action) {
5271
- const latestSpec = state.specifications[state.specifications.length - 1];
5272
- for (let i = 0; i < latestSpec.modules.length; i++) if (latestSpec.modules[i].id === action.input.id) latestSpec.modules[i].description = action.input.description || "";
5407
+ const targetModule = findModuleOrThrow(state, action.input.id);
5408
+ targetModule.description = action.input.description || "";
5273
5409
  },
5274
5410
  deleteModuleOperation(state, action) {
5411
+ findModuleOrThrow(state, action.input.id);
5275
5412
  const latestSpec = state.specifications[state.specifications.length - 1];
5276
5413
  latestSpec.modules = latestSpec.modules.filter((m) => m.id != action.input.id);
5277
5414
  },
5278
5415
  reorderModulesOperation(state, action) {
5279
- state.specifications[state.specifications.length - 1].modules.sort(sorter(action.input.order));
5416
+ const latestSpec = state.specifications[state.specifications.length - 1];
5417
+ latestSpec.modules = orderBy(latestSpec.modules, action.input.order);
5280
5418
  }
5281
5419
  };
5282
5420
  const documentModelOperationErrorReducer = {
5283
5421
  addOperationErrorOperation(state, action) {
5284
- findOperationOrThrow(state, action.input.operationId).errors.push({
5422
+ const targetOp = findOperationOrThrow(state, action.input.operationId);
5423
+ assertOperationErrorIdUnique(state, action.input.id);
5424
+ targetOp.errors.push({
5285
5425
  id: action.input.id,
5286
5426
  name: action.input.errorName || "",
5287
5427
  code: action.input.errorCode || "",
@@ -5290,54 +5430,58 @@ const documentModelOperationErrorReducer = {
5290
5430
  });
5291
5431
  },
5292
5432
  setOperationErrorCodeOperation(state, action) {
5293
- const latestSpec = state.specifications[state.specifications.length - 1];
5294
- 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 || "";
5433
+ const error = findOperationErrorOrThrow(state, action.input.id);
5434
+ error.code = action.input.errorCode || "";
5295
5435
  },
5296
5436
  setOperationErrorNameOperation(state, action) {
5297
- const latestSpec = state.specifications[state.specifications.length - 1];
5298
- 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 || "";
5437
+ const error = findOperationErrorOrThrow(state, action.input.id);
5438
+ error.name = action.input.errorName || "";
5299
5439
  },
5300
5440
  setOperationErrorDescriptionOperation(state, action) {
5301
- const latestSpec = state.specifications[state.specifications.length - 1];
5302
- 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 || "";
5441
+ const error = findOperationErrorOrThrow(state, action.input.id);
5442
+ error.description = action.input.errorDescription || "";
5303
5443
  },
5304
5444
  setOperationErrorTemplateOperation(state, action) {
5305
- const latestSpec = state.specifications[state.specifications.length - 1];
5306
- 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 || "";
5445
+ const error = findOperationErrorOrThrow(state, action.input.id);
5446
+ error.template = action.input.errorTemplate || "";
5307
5447
  },
5308
5448
  deleteOperationErrorOperation(state, action) {
5309
5449
  const latestSpec = state.specifications[state.specifications.length - 1];
5310
- 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);
5450
+ 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`);
5451
+ for (const mod of latestSpec.modules) for (const op of mod.operations) op.errors = op.errors.filter((e) => e.id != action.input.id);
5311
5452
  },
5312
5453
  reorderOperationErrorsOperation(state, action) {
5313
- const latestSpec = state.specifications[state.specifications.length - 1];
5314
- 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));
5454
+ const targetOp = findOperationOrThrow(state, action.input.operationId);
5455
+ targetOp.errors = orderBy(targetOp.errors, action.input.order);
5315
5456
  }
5316
5457
  };
5317
5458
  const documentModelOperationExampleReducer = {
5318
5459
  addOperationExampleOperation(state, action) {
5319
- const latestSpec = state.specifications[state.specifications.length - 1];
5320
- 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({
5460
+ const targetOp = findOperationOrThrow(state, action.input.operationId);
5461
+ assertOperationExampleIdUnique(state, action.input.id);
5462
+ targetOp.examples.push({
5321
5463
  id: action.input.id,
5322
5464
  value: action.input.example
5323
5465
  });
5324
5466
  },
5325
5467
  updateOperationExampleOperation(state, action) {
5326
- 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++) 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;
5468
+ const example = findOperationExampleOrThrow(state, action.input.id);
5469
+ example.value = action.input.example;
5328
5470
  },
5329
5471
  deleteOperationExampleOperation(state, action) {
5330
5472
  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++) latestSpec.modules[i].operations[j].examples = latestSpec.modules[i].operations[j].examples.filter((e) => e.id != action.input.id);
5473
+ 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`);
5474
+ for (const mod of latestSpec.modules) for (const op of mod.operations) op.examples = op.examples.filter((e) => e.id != action.input.id);
5332
5475
  },
5333
5476
  reorderOperationExamplesOperation(state, action) {
5334
- const latestSpec = state.specifications[state.specifications.length - 1];
5335
- 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));
5477
+ const targetOp = findOperationOrThrow(state, action.input.operationId);
5478
+ targetOp.examples = orderBy(targetOp.examples, action.input.order);
5336
5479
  }
5337
5480
  };
5338
5481
  const documentModelOperationReducer = {
5339
5482
  addOperationOperation(state, action) {
5340
5483
  validateOperationName(action.input.name, state);
5484
+ assertOperationIdUnique(state, action.input.id);
5341
5485
  findModuleOrThrow(state, action.input.moduleId).operations.push({
5342
5486
  id: action.input.id,
5343
5487
  name: action.input.name,
@@ -5352,8 +5496,8 @@ const documentModelOperationReducer = {
5352
5496
  },
5353
5497
  setOperationNameOperation(state, action) {
5354
5498
  if (action.input.name) validateOperationName(action.input.name, state, action.input.id);
5355
- const latestSpec = state.specifications[state.specifications.length - 1];
5356
- 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 || "";
5499
+ const targetOp = findOperationOrThrow(state, action.input.id);
5500
+ targetOp.name = action.input.name || "";
5357
5501
  },
5358
5502
  setOperationScopeOperation(state, action) {
5359
5503
  const targetOp = findOperationOrThrow(state, action.input.id);
@@ -5363,40 +5507,39 @@ const documentModelOperationReducer = {
5363
5507
  targetOp.scope = action.input.scope || "global";
5364
5508
  },
5365
5509
  setOperationSchemaOperation(state, action) {
5366
- const latestSpec = state.specifications[state.specifications.length - 1];
5367
- 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 || "";
5510
+ const targetOp = findOperationOrThrow(state, action.input.id);
5511
+ targetOp.schema = action.input.schema || "";
5368
5512
  },
5369
5513
  setOperationDescriptionOperation(state, action) {
5370
- const latestSpec = state.specifications[state.specifications.length - 1];
5371
- 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 || "";
5514
+ const targetOp = findOperationOrThrow(state, action.input.id);
5515
+ targetOp.description = action.input.description || "";
5372
5516
  },
5373
5517
  setOperationTemplateOperation(state, action) {
5374
- const latestSpec = state.specifications[state.specifications.length - 1];
5375
- 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 || "";
5518
+ const targetOp = findOperationOrThrow(state, action.input.id);
5519
+ targetOp.template = action.input.template || "";
5376
5520
  },
5377
5521
  setOperationReducerOperation(state, action) {
5378
- const latestSpec = state.specifications[state.specifications.length - 1];
5379
- 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 || "";
5522
+ const targetOp = findOperationOrThrow(state, action.input.id);
5523
+ targetOp.reducer = action.input.reducer || "";
5380
5524
  },
5381
5525
  moveOperationOperation(state, action) {
5382
- const moveOperations = [];
5526
+ const targetModule = findModuleOrThrow(state, action.input.newModuleId);
5383
5527
  const latestSpec = state.specifications[state.specifications.length - 1];
5384
- for (let i = 0; i < latestSpec.modules.length; i++) latestSpec.modules[i].operations = latestSpec.modules[i].operations.filter((operation) => {
5385
- if (operation.id == action.input.operationId) {
5386
- moveOperations.push(operation);
5387
- return false;
5388
- }
5389
- return true;
5390
- });
5391
- for (let i = 0; i < latestSpec.modules.length; i++) if (latestSpec.modules[i].id == action.input.newModuleId) latestSpec.modules[i].operations.push(...moveOperations);
5528
+ const matches = latestSpec.modules.flatMap((mod) => mod.operations.filter((op) => op.id === action.input.operationId));
5529
+ if (matches.length === 0) throw new Error(`Operation "${action.input.operationId}" not found in the latest specification`);
5530
+ if (matches.length > 1) throw new Error(`Operation "${action.input.operationId}" is duplicated in the latest specification`);
5531
+ const moved = matches[0];
5532
+ for (const mod of latestSpec.modules) mod.operations = mod.operations.filter((op) => op.id !== action.input.operationId);
5533
+ targetModule.operations.push(moved);
5392
5534
  },
5393
5535
  deleteOperationOperation(state, action) {
5536
+ findOperationOrThrow(state, action.input.id);
5394
5537
  const latestSpec = state.specifications[state.specifications.length - 1];
5395
- for (let i = 0; i < latestSpec.modules.length; i++) latestSpec.modules[i].operations = latestSpec.modules[i].operations.filter((operation) => operation.id != action.input.id);
5538
+ for (const mod of latestSpec.modules) mod.operations = mod.operations.filter((operation) => operation.id != action.input.id);
5396
5539
  },
5397
5540
  reorderModuleOperationsOperation(state, action) {
5398
- const latestSpec = state.specifications[state.specifications.length - 1];
5399
- 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));
5541
+ const targetModule = findModuleOrThrow(state, action.input.moduleId);
5542
+ targetModule.operations = orderBy(targetModule.operations, action.input.order);
5400
5543
  }
5401
5544
  };
5402
5545
  const documentModelStateSchemaReducer = {
@@ -5421,18 +5564,22 @@ const documentModelStateSchemaReducer = {
5421
5564
  updateStateExampleOperation(state, action) {
5422
5565
  const latestSpec = state.specifications[state.specifications.length - 1];
5423
5566
  if (!Object.keys(latestSpec.state).includes(action.input.scope)) throw new Error(`Invalid scope: ${action.input.scope}`);
5424
- const examples = latestSpec.state[action.input.scope].examples;
5425
- for (let i = 0; i < examples.length; i++) if (examples[i].id == action.input.id) examples[i].value = action.input.newExample;
5567
+ const example = latestSpec.state[action.input.scope].examples.find((e) => e.id == action.input.id);
5568
+ if (!example) throw new Error(`State example "${action.input.id}" not found in scope "${action.input.scope}"`);
5569
+ example.value = action.input.newExample;
5426
5570
  },
5427
5571
  deleteStateExampleOperation(state, action) {
5428
5572
  const latestSpec = state.specifications[state.specifications.length - 1];
5429
- 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);
5430
- else throw new Error(`Invalid scope: ${action.input.scope}`);
5573
+ if (!Object.keys(latestSpec.state).includes(action.input.scope)) throw new Error(`Invalid scope: ${action.input.scope}`);
5574
+ const scopeState = latestSpec.state[action.input.scope];
5575
+ 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}"`);
5576
+ scopeState.examples = scopeState.examples.filter((e) => e.id != action.input.id);
5431
5577
  },
5432
5578
  reorderStateExamplesOperation(state, action) {
5433
5579
  const latestSpec = state.specifications[state.specifications.length - 1];
5434
- if (Object.keys(latestSpec.state).includes(action.input.scope)) latestSpec.state[action.input.scope].examples.sort(sorter(action.input.order));
5435
- else throw new Error(`Invalid scope: ${action.input.scope}`);
5580
+ if (!Object.keys(latestSpec.state).includes(action.input.scope)) throw new Error(`Invalid scope: ${action.input.scope}`);
5581
+ const scopeState = latestSpec.state[action.input.scope];
5582
+ scopeState.examples = orderBy(scopeState.examples, action.input.order);
5436
5583
  }
5437
5584
  };
5438
5585
  const documentModelVersioningReducer = {
@@ -5831,6 +5978,211 @@ function createState(baseState, globalState, localState) {
5831
5978
  };
5832
5979
  }
5833
5980
  //#endregion
5981
+ //#region ../document-model/dist/index.js
5982
+ const isStateOfType$1 = (state) => {
5983
+ return isDocumentModelState(state);
5984
+ };
5985
+ const assertIsStateOfType$1 = (state) => {
5986
+ assertIsDocumentModelState(state);
5987
+ };
5988
+ const isDocumentOfType$1 = (document) => {
5989
+ return isDocumentModelDocument(document);
5990
+ };
5991
+ const assertIsDocumentOfType$1 = (document) => {
5992
+ assertIsDocumentModelDocument(document);
5993
+ };
5994
+ const documentModelCreateState = (state) => {
5995
+ return {
5996
+ ...defaultBaseState(),
5997
+ global: {
5998
+ ...documentModelInitialGlobalState,
5999
+ ...state?.global ?? {}
6000
+ },
6001
+ local: {
6002
+ ...documentModelInitialLocalState,
6003
+ ...state?.local ?? {}
6004
+ }
6005
+ };
6006
+ };
6007
+ function documentModelCreateDocument(state) {
6008
+ return baseCreateDocument(documentModelCreateState, state, documentModelDocumentType);
6009
+ }
6010
+ const utils = {
6011
+ fileExtension: documentModelFileExtension,
6012
+ createState: documentModelCreateState,
6013
+ createDocument: documentModelCreateDocument,
6014
+ loadFromInput: documentModelLoadFromInput,
6015
+ saveToFileHandle: documentModelSaveToFileHandle,
6016
+ isStateOfType: isStateOfType$1,
6017
+ assertIsStateOfType: assertIsStateOfType$1,
6018
+ isDocumentOfType: isDocumentOfType$1,
6019
+ assertIsDocumentOfType: assertIsDocumentOfType$1
6020
+ };
6021
+ const documentModelDocumentModelModule = {
6022
+ reducer: documentModelReducer,
6023
+ documentModel: createState(defaultBaseState(), documentModelGlobalState),
6024
+ actions,
6025
+ utils
6026
+ };
6027
+ (class PHDocumentController {
6028
+ module;
6029
+ _document;
6030
+ listeners = [];
6031
+ constructor(module, initialDocument) {
6032
+ this.module = module;
6033
+ this._document = initialDocument ?? module.utils.createDocument();
6034
+ for (const actionType in this.module.actions) Object.defineProperty(this, actionType, { value: (input) => {
6035
+ const action = this.module.actions[actionType](input);
6036
+ this._document = this.module.reducer(this._document, action);
6037
+ this.notifyListeners();
6038
+ return this;
6039
+ } });
6040
+ }
6041
+ get document() {
6042
+ return this._document;
6043
+ }
6044
+ get header() {
6045
+ return this.document.header;
6046
+ }
6047
+ get state() {
6048
+ return this.document.state;
6049
+ }
6050
+ get initialState() {
6051
+ return this.document.initialState;
6052
+ }
6053
+ get operations() {
6054
+ return this.document.operations;
6055
+ }
6056
+ get clipboard() {
6057
+ return this.document.clipboard;
6058
+ }
6059
+ onChange(listener) {
6060
+ this.listeners.push(listener);
6061
+ return () => {
6062
+ this.listeners = this.listeners.filter((l) => l !== listener);
6063
+ };
6064
+ }
6065
+ notifyListeners() {
6066
+ if (this.listeners.length === 0) return;
6067
+ const event = { document: this._document };
6068
+ for (const listener of this.listeners) listener(event);
6069
+ }
6070
+ static forDocumentModel(module) {
6071
+ return class extends PHDocumentController {
6072
+ constructor(initialDocument) {
6073
+ super(module, initialDocument);
6074
+ }
6075
+ };
6076
+ }
6077
+ }).forDocumentModel(documentModelDocumentModelModule);
6078
+ const tokenSub = /@([a-zA-Z0-9_]+)/g;
6079
+ const dtf = new Intl.DateTimeFormat(void 0, {
6080
+ hour12: false,
6081
+ hour: "2-digit",
6082
+ minute: "2-digit",
6083
+ second: "2-digit",
6084
+ fractionalSecondDigits: 2
6085
+ });
6086
+ const stringify = (value, includeStack) => {
6087
+ if (value === null || value === void 0) return "null";
6088
+ if (typeof value === "string") return value;
6089
+ if (value instanceof Error) {
6090
+ const base = `${value.name}: ${value.message}`;
6091
+ return includeStack && value.stack ? `${base}\n${value.stack}` : base;
6092
+ }
6093
+ if (typeof value === "object") try {
6094
+ return JSON.stringify(value);
6095
+ } catch {
6096
+ return Object.prototype.toString.call(value);
6097
+ }
6098
+ if (typeof value === "function") {
6099
+ const name = value.name;
6100
+ return name ? `${name}()` : "anonymous()";
6101
+ }
6102
+ return String(value);
6103
+ };
6104
+ const formatMessage = (tagString, message, replacements, includeStack) => {
6105
+ const meta = {};
6106
+ const uniqueTokens = [];
6107
+ let results;
6108
+ while ((results = tokenSub.exec(message)) !== null) {
6109
+ const tokenName = results[1];
6110
+ if (uniqueTokens.indexOf(tokenName) === -1) {
6111
+ uniqueTokens.push(tokenName);
6112
+ meta[tokenName] = replacements[uniqueTokens.length - 1];
6113
+ }
6114
+ }
6115
+ for (const [key, value] of Object.entries(meta)) message = message.replaceAll(`@${key}`, stringify(value, includeStack));
6116
+ const extras = replacements.slice(uniqueTokens.length);
6117
+ if (extras.length > 0) message = `${message} ${extras.map((v) => stringify(v, includeStack)).join(" ")}`;
6118
+ if (tagString.length > 0) message = `${tagString} ${message}`;
6119
+ const now = /* @__PURE__ */ new Date();
6120
+ meta["timestamp"] = dtf.format(now);
6121
+ return [message, meta];
6122
+ };
6123
+ const LOG_LEVELS = {
6124
+ verbose: 0,
6125
+ debug: 1,
6126
+ info: 2,
6127
+ warn: 3,
6128
+ error: 4
6129
+ };
6130
+ const logger = new class ConsoleLogger {
6131
+ #tags;
6132
+ #tagString;
6133
+ #level = LOG_LEVELS.info;
6134
+ errorHandler;
6135
+ constructor(tags, handler) {
6136
+ this.#tags = tags || [];
6137
+ this.#tagString = this.#tags.map((tag) => `[${tag}]`).join("");
6138
+ this.errorHandler = handler ?? (() => {});
6139
+ }
6140
+ get level() {
6141
+ return Object.keys(LOG_LEVELS).find((key) => LOG_LEVELS[key] === this.#level);
6142
+ }
6143
+ set level(value) {
6144
+ this.#level = LOG_LEVELS[value];
6145
+ }
6146
+ child(tags) {
6147
+ const logger = new ConsoleLogger([...this.#tags, ...tags], this.errorHandler);
6148
+ logger.level = this.level;
6149
+ return logger;
6150
+ }
6151
+ get #includeStack() {
6152
+ return this.#level <= LOG_LEVELS.debug;
6153
+ }
6154
+ verbose(message, ...replacements) {
6155
+ if (this.#level <= LOG_LEVELS.verbose) {
6156
+ const [formattedMessage, meta] = formatMessage(this.#tagString, message, replacements, this.#includeStack);
6157
+ console.debug(`[${meta["timestamp"]}] ${formattedMessage}`);
6158
+ }
6159
+ }
6160
+ debug(message, ...replacements) {
6161
+ if (this.#level <= LOG_LEVELS.debug) {
6162
+ const [formattedMessage, meta] = formatMessage(this.#tagString, message, replacements, this.#includeStack);
6163
+ console.debug(`[${meta["timestamp"]}] ${formattedMessage}`);
6164
+ }
6165
+ }
6166
+ info(message, ...replacements) {
6167
+ if (this.#level <= LOG_LEVELS.info) {
6168
+ const [formattedMessage, meta] = formatMessage(this.#tagString, message, replacements, this.#includeStack);
6169
+ console.info(`[${meta["timestamp"]}] ${formattedMessage}`);
6170
+ }
6171
+ }
6172
+ warn(message, ...replacements) {
6173
+ if (this.#level <= LOG_LEVELS.warn) {
6174
+ const [formattedMessage, meta] = formatMessage(this.#tagString, message, replacements, this.#includeStack);
6175
+ console.warn(`[${meta["timestamp"]}] ${formattedMessage}`);
6176
+ }
6177
+ }
6178
+ error(message, ...replacements) {
6179
+ if (this.#level <= LOG_LEVELS.error) {
6180
+ const [formattedMessage, meta] = formatMessage(this.#tagString, message, replacements, this.#includeStack);
6181
+ console.error(`[${meta["timestamp"]}] ${formattedMessage}`);
6182
+ }
6183
+ }
6184
+ }();
6185
+ //#endregion
5834
6186
  //#region ../shared/dist/document-drive/index.js
5835
6187
  var __defProp = Object.defineProperty;
5836
6188
  var __exportAll = (all, no_symbols) => {
@@ -6436,12 +6788,12 @@ function handleTargetNameCollisions(params) {
6436
6788
  return targetNodeChildrenNames.includes(srcName) ? `${srcName} (copy) ${getNextCopyNumber(targetNodeChildrenNames, srcName)}` : srcName;
6437
6789
  }
6438
6790
  const isValidName = (name) => {
6439
- return /^[a-zA-Z0-9-_.\s()]+$/.test(name);
6791
+ return name.trim().length > 0 && !/[\u0000-\u001F\u007F]/.test(name);
6440
6792
  };
6441
6793
  const nodeReducer = {
6442
6794
  addFileOperation(state, action, dispatch) {
6443
6795
  if (state.nodes.find((node) => node.id === action.input.id)) throw new Error(`Node with id ${action.input.id} already exists!`);
6444
- if (!isValidName(action.input.name)) throw new Error(`Invalid name: '${action.input.name}'. Names must be valid URL characters.`);
6796
+ if (!isValidName(action.input.name)) throw new Error(`Invalid name: '${action.input.name}'. Names must not be empty or contain control characters.`);
6445
6797
  const name = handleTargetNameCollisions({
6446
6798
  nodes: state.nodes,
6447
6799
  srcName: action.input.name,
@@ -6467,7 +6819,7 @@ const nodeReducer = {
6467
6819
  },
6468
6820
  addFolderOperation(state, action) {
6469
6821
  if (state.nodes.find((node) => node.id === action.input.id)) throw new Error(`Node with id ${action.input.id} already exists!`);
6470
- if (!isValidName(action.input.name)) throw new Error(`Invalid name: '${action.input.name}'. Names must be valid URL characters.`);
6822
+ if (!isValidName(action.input.name)) throw new Error(`Invalid name: '${action.input.name}'. Names must not be empty or contain control characters.`);
6471
6823
  const name = handleTargetNameCollisions({
6472
6824
  nodes: state.nodes,
6473
6825
  srcName: action.input.name,
@@ -6495,7 +6847,7 @@ const nodeReducer = {
6495
6847
  });
6496
6848
  },
6497
6849
  updateFileOperation(state, action) {
6498
- if (action.input.name && !isValidName(action.input.name)) throw new Error(`Invalid name: '${action.input.name}'. Names must be valid URL characters.`);
6850
+ 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.`);
6499
6851
  state.nodes = state.nodes.map((node) => node.id === action.input.id ? {
6500
6852
  ...node,
6501
6853
  name: handleTargetNameCollisions({
@@ -6509,7 +6861,7 @@ const nodeReducer = {
6509
6861
  state.nodes.sort((a, b) => a.id.localeCompare(b.id));
6510
6862
  },
6511
6863
  updateNodeOperation(state, action) {
6512
- if (action.input.name && !isValidName(action.input.name)) throw new Error(`Invalid name: '${action.input.name}'. Names must be valid URL characters.`);
6864
+ 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.`);
6513
6865
  state.nodes = state.nodes.map((node) => node.id === action.input.id ? {
6514
6866
  ...node,
6515
6867
  name: handleTargetNameCollisions({
@@ -6666,10 +7018,7 @@ const driveCreateState = (state) => {
6666
7018
  };
6667
7019
  };
6668
7020
  const driveCreateDocument = (state) => {
6669
- const document = baseCreateDocument(driveCreateState, state);
6670
- document.header.documentType = driveDocumentType;
6671
- document.header.id = generateId();
6672
- return document;
7021
+ return baseCreateDocument(driveCreateState, state, driveDocumentType);
6673
7022
  };
6674
7023
  const driveSaveToFileHandle = (document, input) => {
6675
7024
  return baseSaveToFileHandle(document, input);
@@ -6677,16 +7026,16 @@ const driveSaveToFileHandle = (document, input) => {
6677
7026
  const driveLoadFromInput = (input) => {
6678
7027
  return baseLoadFromInput(input, driveDocumentReducer);
6679
7028
  };
6680
- const isStateOfType$1 = (state) => {
7029
+ const isStateOfType = (state) => {
6681
7030
  return isDriveState(state);
6682
7031
  };
6683
- const assertIsStateOfType$1 = (state) => {
7032
+ const assertIsStateOfType = (state) => {
6684
7033
  assertIsDriveState(state);
6685
7034
  };
6686
- const isDocumentOfType$1 = (document) => {
7035
+ const isDocumentOfType = (document) => {
6687
7036
  return isDriveDocument(document);
6688
7037
  };
6689
- const assertIsDocumentOfType$1 = (document) => {
7038
+ const assertIsDocumentOfType = (document) => {
6690
7039
  assertIsDriveDocument(document);
6691
7040
  };
6692
7041
  const driveDocumentModelModule = {
@@ -6699,220 +7048,13 @@ const driveDocumentModelModule = {
6699
7048
  createDocument: driveCreateDocument,
6700
7049
  loadFromInput: driveLoadFromInput,
6701
7050
  saveToFileHandle: driveSaveToFileHandle,
6702
- isStateOfType: isStateOfType$1,
6703
- assertIsStateOfType: assertIsStateOfType$1,
6704
- isDocumentOfType: isDocumentOfType$1,
6705
- assertIsDocumentOfType: assertIsDocumentOfType$1
7051
+ isStateOfType,
7052
+ assertIsStateOfType,
7053
+ isDocumentOfType,
7054
+ assertIsDocumentOfType
6706
7055
  }
6707
7056
  };
6708
7057
  //#endregion
6709
- //#region ../document-model/dist/index.js
6710
- const isStateOfType = (state) => {
6711
- return isDocumentModelState(state);
6712
- };
6713
- const assertIsStateOfType = (state) => {
6714
- assertIsDocumentModelState(state);
6715
- };
6716
- const isDocumentOfType = (document) => {
6717
- return isDocumentModelDocument(document);
6718
- };
6719
- const assertIsDocumentOfType = (document) => {
6720
- assertIsDocumentModelDocument(document);
6721
- };
6722
- const documentModelCreateState = (state) => {
6723
- return {
6724
- ...defaultBaseState(),
6725
- global: {
6726
- ...documentModelInitialGlobalState,
6727
- ...state?.global ?? {}
6728
- },
6729
- local: {
6730
- ...documentModelInitialLocalState,
6731
- ...state?.local ?? {}
6732
- }
6733
- };
6734
- };
6735
- function documentModelCreateDocument(state) {
6736
- const document = baseCreateDocument(documentModelCreateState, state);
6737
- document.header.documentType = documentModelDocumentType;
6738
- return document;
6739
- }
6740
- const utils = {
6741
- fileExtension: documentModelFileExtension,
6742
- createState: documentModelCreateState,
6743
- createDocument: documentModelCreateDocument,
6744
- loadFromInput: documentModelLoadFromInput,
6745
- saveToFileHandle: documentModelSaveToFileHandle,
6746
- isStateOfType,
6747
- assertIsStateOfType,
6748
- isDocumentOfType,
6749
- assertIsDocumentOfType
6750
- };
6751
- const documentModelDocumentModelModule = {
6752
- reducer: documentModelReducer,
6753
- documentModel: createState(defaultBaseState(), documentModelGlobalState),
6754
- actions,
6755
- utils
6756
- };
6757
- (class PHDocumentController {
6758
- module;
6759
- _document;
6760
- listeners = [];
6761
- constructor(module, initialDocument) {
6762
- this.module = module;
6763
- this._document = initialDocument ?? module.utils.createDocument();
6764
- for (const actionType in this.module.actions) Object.defineProperty(this, actionType, { value: (input) => {
6765
- const action = this.module.actions[actionType](input);
6766
- this._document = this.module.reducer(this._document, action);
6767
- this.notifyListeners();
6768
- return this;
6769
- } });
6770
- }
6771
- get document() {
6772
- return this._document;
6773
- }
6774
- get header() {
6775
- return this.document.header;
6776
- }
6777
- get state() {
6778
- return this.document.state;
6779
- }
6780
- get initialState() {
6781
- return this.document.initialState;
6782
- }
6783
- get operations() {
6784
- return this.document.operations;
6785
- }
6786
- get clipboard() {
6787
- return this.document.clipboard;
6788
- }
6789
- onChange(listener) {
6790
- this.listeners.push(listener);
6791
- return () => {
6792
- this.listeners = this.listeners.filter((l) => l !== listener);
6793
- };
6794
- }
6795
- notifyListeners() {
6796
- if (this.listeners.length === 0) return;
6797
- const event = { document: this._document };
6798
- for (const listener of this.listeners) listener(event);
6799
- }
6800
- static forDocumentModel(module) {
6801
- return class extends PHDocumentController {
6802
- constructor(initialDocument) {
6803
- super(module, initialDocument);
6804
- }
6805
- };
6806
- }
6807
- }).forDocumentModel(documentModelDocumentModelModule);
6808
- const tokenSub = /@([a-zA-Z0-9_]+)/g;
6809
- const dtf = new Intl.DateTimeFormat(void 0, {
6810
- hour12: false,
6811
- hour: "2-digit",
6812
- minute: "2-digit",
6813
- second: "2-digit",
6814
- fractionalSecondDigits: 2
6815
- });
6816
- const stringify = (value, includeStack) => {
6817
- if (value === null || value === void 0) return "null";
6818
- if (typeof value === "string") return value;
6819
- if (value instanceof Error) {
6820
- const base = `${value.name}: ${value.message}`;
6821
- return includeStack && value.stack ? `${base}\n${value.stack}` : base;
6822
- }
6823
- if (typeof value === "object") try {
6824
- return JSON.stringify(value);
6825
- } catch {
6826
- return String(value);
6827
- }
6828
- if (typeof value === "function") {
6829
- const name = value.name;
6830
- return name ? `${name}()` : "anonymous()";
6831
- }
6832
- return String(value);
6833
- };
6834
- const formatMessage = (tagString, message, replacements, includeStack) => {
6835
- const meta = {};
6836
- const uniqueTokens = [];
6837
- let results;
6838
- while ((results = tokenSub.exec(message)) !== null) {
6839
- const tokenName = results[1];
6840
- if (uniqueTokens.indexOf(tokenName) === -1) {
6841
- uniqueTokens.push(tokenName);
6842
- meta[tokenName] = replacements[uniqueTokens.length - 1];
6843
- }
6844
- }
6845
- for (const [key, value] of Object.entries(meta)) message = message.replaceAll(`@${key}`, stringify(value, includeStack));
6846
- const extras = replacements.slice(uniqueTokens.length);
6847
- if (extras.length > 0) message = `${message} ${extras.map((v) => stringify(v, includeStack)).join(" ")}`;
6848
- if (tagString.length > 0) message = `${tagString} ${message}`;
6849
- const now = /* @__PURE__ */ new Date();
6850
- meta["timestamp"] = dtf.format(now);
6851
- return [message, meta];
6852
- };
6853
- const LOG_LEVELS = {
6854
- verbose: 0,
6855
- debug: 1,
6856
- info: 2,
6857
- warn: 3,
6858
- error: 4
6859
- };
6860
- const logger = new class ConsoleLogger {
6861
- #tags;
6862
- #tagString;
6863
- #level = LOG_LEVELS.info;
6864
- errorHandler;
6865
- constructor(tags, handler) {
6866
- this.#tags = tags || [];
6867
- this.#tagString = this.#tags.map((tag) => `[${tag}]`).join("");
6868
- this.errorHandler = handler ?? (() => {});
6869
- }
6870
- get level() {
6871
- return Object.keys(LOG_LEVELS).find((key) => LOG_LEVELS[key] === this.#level);
6872
- }
6873
- set level(value) {
6874
- this.#level = LOG_LEVELS[value];
6875
- }
6876
- child(tags) {
6877
- const logger = new ConsoleLogger([...this.#tags, ...tags], this.errorHandler);
6878
- logger.level = this.level;
6879
- return logger;
6880
- }
6881
- get #includeStack() {
6882
- return this.#level <= LOG_LEVELS.debug;
6883
- }
6884
- verbose(message, ...replacements) {
6885
- if (this.#level <= LOG_LEVELS.verbose) {
6886
- const [formattedMessage, meta] = formatMessage(this.#tagString, message, replacements, this.#includeStack);
6887
- console.debug(`[${meta["timestamp"]}] ${formattedMessage}`);
6888
- }
6889
- }
6890
- debug(message, ...replacements) {
6891
- if (this.#level <= LOG_LEVELS.debug) {
6892
- const [formattedMessage, meta] = formatMessage(this.#tagString, message, replacements, this.#includeStack);
6893
- console.debug(`[${meta["timestamp"]}] ${formattedMessage}`);
6894
- }
6895
- }
6896
- info(message, ...replacements) {
6897
- if (this.#level <= LOG_LEVELS.info) {
6898
- const [formattedMessage, meta] = formatMessage(this.#tagString, message, replacements, this.#includeStack);
6899
- console.info(`[${meta["timestamp"]}] ${formattedMessage}`);
6900
- }
6901
- }
6902
- warn(message, ...replacements) {
6903
- if (this.#level <= LOG_LEVELS.warn) {
6904
- const [formattedMessage, meta] = formatMessage(this.#tagString, message, replacements, this.#includeStack);
6905
- console.warn(`[${meta["timestamp"]}] ${formattedMessage}`);
6906
- }
6907
- }
6908
- error(message, ...replacements) {
6909
- if (this.#level <= LOG_LEVELS.error) {
6910
- const [formattedMessage, meta] = formatMessage(this.#tagString, message, replacements, this.#includeStack);
6911
- console.error(`[${meta["timestamp"]}] ${formattedMessage}`);
6912
- }
6913
- }
6914
- }();
6915
- //#endregion
6916
- 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 };
7058
+ 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 };
6917
7059
 
6918
- //# sourceMappingURL=dist-DQgJ8n4d.js.map
7060
+ //# sourceMappingURL=document-drive-oqv68jDU.js.map