@superdoc-dev/cli 0.2.0-next.55 → 0.2.0-next.57

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 (2) hide show
  1. package/dist/index.js +1583 -284
  2. package/package.json +9 -9
package/dist/index.js CHANGED
@@ -1956,19 +1956,49 @@ var init_operation_definitions = __esm(() => {
1956
1956
  referenceDocPath: "lists/insert.mdx",
1957
1957
  referenceGroup: "lists"
1958
1958
  },
1959
- "lists.setType": {
1960
- memberPath: "lists.setType",
1961
- description: "Change the list type (ordered, unordered) of a target list.",
1962
- expectedResult: "Returns a ListsMutateItemResult receipt; reports NO_OP if the list already has the requested type.",
1959
+ "lists.create": {
1960
+ memberPath: "lists.create",
1961
+ description: "Create a new list from one or more paragraphs, or convert existing paragraphs into a new list.",
1962
+ expectedResult: "Returns a ListsCreateResult with the new listId and the first item address.",
1963
+ requiresDocumentContext: true,
1964
+ metadata: mutationOperation({
1965
+ idempotency: "non-idempotent",
1966
+ supportsDryRun: true,
1967
+ supportsTrackedMode: false,
1968
+ possibleFailureCodes: ["INVALID_TARGET", "LEVEL_OUT_OF_RANGE"],
1969
+ throws: [...T_NOT_FOUND_CAPABLE, "INVALID_TARGET"]
1970
+ }),
1971
+ referenceDocPath: "lists/create.mdx",
1972
+ referenceGroup: "lists"
1973
+ },
1974
+ "lists.attach": {
1975
+ memberPath: "lists.attach",
1976
+ description: "Convert non-list paragraphs to list items under an existing list sequence.",
1977
+ expectedResult: "Returns a ListsMutateItemResult confirming attachment.",
1978
+ requiresDocumentContext: true,
1979
+ metadata: mutationOperation({
1980
+ idempotency: "conditional",
1981
+ supportsDryRun: true,
1982
+ supportsTrackedMode: false,
1983
+ possibleFailureCodes: ["INVALID_TARGET", "NO_OP"],
1984
+ throws: [...T_NOT_FOUND_CAPABLE, "INVALID_TARGET"]
1985
+ }),
1986
+ referenceDocPath: "lists/attach.mdx",
1987
+ referenceGroup: "lists"
1988
+ },
1989
+ "lists.detach": {
1990
+ memberPath: "lists.detach",
1991
+ description: "Remove numbering properties from list items, converting them to plain paragraphs.",
1992
+ expectedResult: "Returns a ListsDetachResult confirming the item was converted to a plain paragraph.",
1963
1993
  requiresDocumentContext: true,
1964
1994
  metadata: mutationOperation({
1965
1995
  idempotency: "conditional",
1966
1996
  supportsDryRun: true,
1967
1997
  supportsTrackedMode: false,
1968
- possibleFailureCodes: ["NO_OP", "INVALID_TARGET"],
1998
+ possibleFailureCodes: ["INVALID_TARGET"],
1969
1999
  throws: [...T_NOT_FOUND_CAPABLE, "INVALID_TARGET"]
1970
2000
  }),
1971
- referenceDocPath: "lists/set-type.mdx",
2001
+ referenceDocPath: "lists/detach.mdx",
1972
2002
  referenceGroup: "lists"
1973
2003
  },
1974
2004
  "lists.indent": {
@@ -1980,7 +2010,7 @@ var init_operation_definitions = __esm(() => {
1980
2010
  idempotency: "conditional",
1981
2011
  supportsDryRun: true,
1982
2012
  supportsTrackedMode: false,
1983
- possibleFailureCodes: ["NO_OP", "INVALID_TARGET"],
2013
+ possibleFailureCodes: ["NO_OP", "INVALID_TARGET", "LEVEL_OUT_OF_RANGE"],
1984
2014
  throws: [...T_NOT_FOUND_CAPABLE, "INVALID_TARGET"]
1985
2015
  }),
1986
2016
  referenceDocPath: "lists/indent.mdx",
@@ -1995,31 +2025,135 @@ var init_operation_definitions = __esm(() => {
1995
2025
  idempotency: "conditional",
1996
2026
  supportsDryRun: true,
1997
2027
  supportsTrackedMode: false,
1998
- possibleFailureCodes: ["NO_OP", "INVALID_TARGET"],
2028
+ possibleFailureCodes: ["NO_OP", "INVALID_TARGET", "LEVEL_OUT_OF_RANGE"],
1999
2029
  throws: [...T_NOT_FOUND_CAPABLE, "INVALID_TARGET"]
2000
2030
  }),
2001
2031
  referenceDocPath: "lists/outdent.mdx",
2002
2032
  referenceGroup: "lists"
2003
2033
  },
2004
- "lists.restart": {
2005
- memberPath: "lists.restart",
2006
- description: "Restart numbering of an ordered list at the target item.",
2007
- expectedResult: "Returns a ListsMutateItemResult receipt; reports NO_OP if numbering already restarts at the target item.",
2034
+ "lists.join": {
2035
+ memberPath: "lists.join",
2036
+ description: "Merge two adjacent list sequences into one.",
2037
+ expectedResult: "Returns a ListsJoinResult with the resulting listId of the merged sequence.",
2038
+ requiresDocumentContext: true,
2039
+ metadata: mutationOperation({
2040
+ idempotency: "conditional",
2041
+ supportsDryRun: true,
2042
+ supportsTrackedMode: false,
2043
+ possibleFailureCodes: [
2044
+ "INVALID_TARGET",
2045
+ "NO_ADJACENT_SEQUENCE",
2046
+ "INCOMPATIBLE_DEFINITIONS",
2047
+ "ALREADY_SAME_SEQUENCE"
2048
+ ],
2049
+ throws: [...T_NOT_FOUND_CAPABLE, "INVALID_TARGET"]
2050
+ }),
2051
+ referenceDocPath: "lists/join.mdx",
2052
+ referenceGroup: "lists"
2053
+ },
2054
+ "lists.canJoin": {
2055
+ memberPath: "lists.canJoin",
2056
+ description: "Check whether two adjacent list sequences can be joined.",
2057
+ expectedResult: "Returns a ListsCanJoinResult indicating feasibility and reason if not possible.",
2058
+ requiresDocumentContext: true,
2059
+ metadata: readOperation({
2060
+ idempotency: "idempotent",
2061
+ throws: ["TARGET_NOT_FOUND", "INVALID_TARGET", "INVALID_INPUT"]
2062
+ }),
2063
+ referenceDocPath: "lists/can-join.mdx",
2064
+ referenceGroup: "lists"
2065
+ },
2066
+ "lists.separate": {
2067
+ memberPath: "lists.separate",
2068
+ description: "Split a list sequence at the target item, creating a new sequence from that point forward.",
2069
+ expectedResult: "Returns a ListsSeparateResult with the new listId and numId.",
2070
+ requiresDocumentContext: true,
2071
+ metadata: mutationOperation({
2072
+ idempotency: "conditional",
2073
+ supportsDryRun: true,
2074
+ supportsTrackedMode: false,
2075
+ possibleFailureCodes: ["INVALID_TARGET", "NO_OP"],
2076
+ throws: [...T_NOT_FOUND_CAPABLE, "INVALID_TARGET"]
2077
+ }),
2078
+ referenceDocPath: "lists/separate.mdx",
2079
+ referenceGroup: "lists"
2080
+ },
2081
+ "lists.setLevel": {
2082
+ memberPath: "lists.setLevel",
2083
+ description: "Set the absolute nesting level (0..8) of a list item.",
2084
+ expectedResult: "Returns a ListsMutateItemResult receipt; reports NO_OP if already at the target level.",
2085
+ requiresDocumentContext: true,
2086
+ metadata: mutationOperation({
2087
+ idempotency: "conditional",
2088
+ supportsDryRun: true,
2089
+ supportsTrackedMode: false,
2090
+ possibleFailureCodes: ["INVALID_TARGET", "LEVEL_OUT_OF_RANGE", "NO_OP"],
2091
+ throws: [...T_NOT_FOUND_CAPABLE, "INVALID_TARGET"]
2092
+ }),
2093
+ referenceDocPath: "lists/set-level.mdx",
2094
+ referenceGroup: "lists"
2095
+ },
2096
+ "lists.setValue": {
2097
+ memberPath: "lists.setValue",
2098
+ description: "Set an explicit numbering value at the target item. Mid-sequence targets are atomically separated first.",
2099
+ expectedResult: "Returns a ListsMutateItemResult receipt.",
2100
+ requiresDocumentContext: true,
2101
+ metadata: mutationOperation({
2102
+ idempotency: "conditional",
2103
+ supportsDryRun: true,
2104
+ supportsTrackedMode: false,
2105
+ possibleFailureCodes: ["INVALID_TARGET", "NO_OP"],
2106
+ throws: [...T_NOT_FOUND_CAPABLE, "INVALID_TARGET"]
2107
+ }),
2108
+ referenceDocPath: "lists/set-value.mdx",
2109
+ referenceGroup: "lists"
2110
+ },
2111
+ "lists.continuePrevious": {
2112
+ memberPath: "lists.continuePrevious",
2113
+ description: "Continue numbering from the nearest compatible previous list sequence.",
2114
+ expectedResult: "Returns a ListsMutateItemResult receipt.",
2008
2115
  requiresDocumentContext: true,
2009
2116
  metadata: mutationOperation({
2010
2117
  idempotency: "conditional",
2011
2118
  supportsDryRun: true,
2012
2119
  supportsTrackedMode: false,
2013
- possibleFailureCodes: ["NO_OP", "INVALID_TARGET"],
2120
+ possibleFailureCodes: ["INVALID_TARGET", "NO_COMPATIBLE_PREVIOUS", "ALREADY_CONTINUOUS"],
2014
2121
  throws: [...T_NOT_FOUND_CAPABLE, "INVALID_TARGET"]
2015
2122
  }),
2016
- referenceDocPath: "lists/restart.mdx",
2123
+ referenceDocPath: "lists/continue-previous.mdx",
2017
2124
  referenceGroup: "lists"
2018
2125
  },
2019
- "lists.exit": {
2020
- memberPath: "lists.exit",
2021
- description: "Exit a list context, converting the target item to a paragraph.",
2022
- expectedResult: "Returns a ListsExitResult confirming the item was converted to a plain paragraph.",
2126
+ "lists.canContinuePrevious": {
2127
+ memberPath: "lists.canContinuePrevious",
2128
+ description: "Check whether the target sequence can continue numbering from a previous compatible sequence.",
2129
+ expectedResult: "Returns a ListsCanContinuePreviousResult indicating feasibility.",
2130
+ requiresDocumentContext: true,
2131
+ metadata: readOperation({
2132
+ idempotency: "idempotent",
2133
+ throws: ["TARGET_NOT_FOUND", "INVALID_TARGET", "INVALID_INPUT"]
2134
+ }),
2135
+ referenceDocPath: "lists/can-continue-previous.mdx",
2136
+ referenceGroup: "lists"
2137
+ },
2138
+ "lists.setLevelRestart": {
2139
+ memberPath: "lists.setLevelRestart",
2140
+ description: "Set the restart behavior for a specific list level.",
2141
+ expectedResult: "Returns a ListsMutateItemResult receipt.",
2142
+ requiresDocumentContext: true,
2143
+ metadata: mutationOperation({
2144
+ idempotency: "conditional",
2145
+ supportsDryRun: true,
2146
+ supportsTrackedMode: false,
2147
+ possibleFailureCodes: ["INVALID_TARGET", "LEVEL_OUT_OF_RANGE"],
2148
+ throws: [...T_NOT_FOUND_CAPABLE, "INVALID_TARGET"]
2149
+ }),
2150
+ referenceDocPath: "lists/set-level-restart.mdx",
2151
+ referenceGroup: "lists"
2152
+ },
2153
+ "lists.convertToText": {
2154
+ memberPath: "lists.convertToText",
2155
+ description: "Convert list items to plain paragraphs, optionally prepending the rendered marker text.",
2156
+ expectedResult: "Returns a ListsConvertToTextResult confirming the conversion.",
2023
2157
  requiresDocumentContext: true,
2024
2158
  metadata: mutationOperation({
2025
2159
  idempotency: "conditional",
@@ -2028,7 +2162,7 @@ var init_operation_definitions = __esm(() => {
2028
2162
  possibleFailureCodes: ["INVALID_TARGET"],
2029
2163
  throws: [...T_NOT_FOUND_CAPABLE, "INVALID_TARGET"]
2030
2164
  }),
2031
- referenceDocPath: "lists/exit.mdx",
2165
+ referenceDocPath: "lists/convert-to-text.mdx",
2032
2166
  referenceGroup: "lists"
2033
2167
  },
2034
2168
  "comments.create": {
@@ -3525,11 +3659,6 @@ function listsMutateItemResultSchemaFor(operationId) {
3525
3659
  oneOf: [listsMutateItemSuccessSchema, listsFailureSchemaFor(operationId)]
3526
3660
  };
3527
3661
  }
3528
- function listsExitResultSchemaFor(operationId) {
3529
- return {
3530
- oneOf: [listsExitSuccessSchema, listsFailureSchemaFor(operationId)]
3531
- };
3532
- }
3533
3662
  function sectionMutationFailureSchemaFor(operationId) {
3534
3663
  return objectSchema({
3535
3664
  success: { const: false },
@@ -3802,7 +3931,19 @@ var init_schemas = __esm(() => {
3802
3931
  }),
3803
3932
  ref: { type: "string" },
3804
3933
  runs: arraySchema(ref("MatchRun"))
3805
- }, ["blockId", "nodeType", "range", "text", "ref", "runs"])
3934
+ }, ["blockId", "nodeType", "range", "text", "ref", "runs"]),
3935
+ BlockAddress: objectSchema({
3936
+ kind: { const: "block" },
3937
+ nodeType: { const: "paragraph" },
3938
+ nodeId: { type: "string" }
3939
+ }, ["kind", "nodeType", "nodeId"]),
3940
+ BlockRange: objectSchema({
3941
+ from: ref("BlockAddress"),
3942
+ to: ref("BlockAddress")
3943
+ }, ["from", "to"]),
3944
+ BlockAddressOrRange: {
3945
+ oneOf: [ref("BlockAddress"), ref("BlockRange")]
3946
+ }
3806
3947
  };
3807
3948
  rangeSchema = ref("Range");
3808
3949
  positionSchema = ref("Position");
@@ -3957,22 +4098,24 @@ var init_schemas = __esm(() => {
3957
4098
  listInsertPositionSchema = { enum: ["before", "after"] };
3958
4099
  listItemInfoSchema = objectSchema({
3959
4100
  address: listItemAddressSchema,
4101
+ listId: { type: "string" },
3960
4102
  marker: { type: "string" },
3961
4103
  ordinal: { type: "integer" },
3962
4104
  path: arraySchema({ type: "integer" }),
3963
4105
  level: { type: "integer" },
3964
4106
  kind: listKindSchema,
3965
4107
  text: { type: "string" }
3966
- }, ["address"]);
4108
+ }, ["address", "listId"]);
3967
4109
  listItemDomainItemSchema = discoveryItemSchema({
3968
4110
  address: listItemAddressSchema,
4111
+ listId: { type: "string" },
3969
4112
  marker: { type: "string" },
3970
4113
  ordinal: { type: "integer" },
3971
4114
  path: arraySchema({ type: "integer" }),
3972
4115
  level: { type: "integer" },
3973
4116
  kind: listKindSchema,
3974
4117
  text: { type: "string" }
3975
- }, ["address"]);
4118
+ }, ["address", "listId"]);
3976
4119
  listsListResultSchema = discoveryResultSchema(listItemDomainItemSchema);
3977
4120
  sectionBreakTypeSchema = { enum: ["continuous", "nextPage", "evenPage", "oddPage"] };
3978
4121
  sectionOrientationSchema = { enum: ["portrait", "landscape"] };
@@ -5066,14 +5209,61 @@ var init_schemas = __esm(() => {
5066
5209
  success: listsInsertSuccessSchema,
5067
5210
  failure: listsFailureSchemaFor("lists.insert")
5068
5211
  },
5069
- "lists.setType": {
5212
+ "lists.create": {
5213
+ input: {
5214
+ type: "object",
5215
+ properties: {
5216
+ mode: { enum: ["empty", "fromParagraphs"] },
5217
+ at: ref("BlockAddress"),
5218
+ target: ref("BlockAddressOrRange"),
5219
+ kind: listKindSchema,
5220
+ level: { type: "integer", minimum: 0, maximum: 8 }
5221
+ },
5222
+ required: ["mode", "kind"],
5223
+ additionalProperties: false,
5224
+ if: { properties: { mode: { const: "empty" } } },
5225
+ then: { required: ["mode", "kind", "at"] },
5226
+ else: { required: ["mode", "kind", "target"] }
5227
+ },
5228
+ output: {
5229
+ oneOf: [
5230
+ objectSchema({ success: { const: true }, listId: { type: "string" }, item: listItemAddressSchema }, [
5231
+ "success",
5232
+ "listId",
5233
+ "item"
5234
+ ]),
5235
+ listsFailureSchemaFor("lists.create")
5236
+ ]
5237
+ },
5238
+ success: objectSchema({ success: { const: true }, listId: { type: "string" }, item: listItemAddressSchema }, [
5239
+ "success",
5240
+ "listId",
5241
+ "item"
5242
+ ]),
5243
+ failure: listsFailureSchemaFor("lists.create")
5244
+ },
5245
+ "lists.attach": {
5070
5246
  input: objectSchema({
5071
- target: listItemAddressSchema,
5072
- kind: listKindSchema
5073
- }, ["target", "kind"]),
5074
- output: listsMutateItemResultSchemaFor("lists.setType"),
5247
+ target: ref("BlockAddressOrRange"),
5248
+ attachTo: listItemAddressSchema,
5249
+ level: { type: "integer", minimum: 0, maximum: 8 }
5250
+ }, ["target", "attachTo"]),
5251
+ output: listsMutateItemResultSchemaFor("lists.attach"),
5075
5252
  success: listsMutateItemSuccessSchema,
5076
- failure: listsFailureSchemaFor("lists.setType")
5253
+ failure: listsFailureSchemaFor("lists.attach")
5254
+ },
5255
+ "lists.detach": {
5256
+ input: objectSchema({
5257
+ target: listItemAddressSchema
5258
+ }, ["target"]),
5259
+ output: {
5260
+ oneOf: [
5261
+ objectSchema({ success: { const: true }, paragraph: ref("ParagraphAddress") }, ["success", "paragraph"]),
5262
+ listsFailureSchemaFor("lists.detach")
5263
+ ]
5264
+ },
5265
+ success: objectSchema({ success: { const: true }, paragraph: ref("ParagraphAddress") }, ["success", "paragraph"]),
5266
+ failure: listsFailureSchemaFor("lists.detach")
5077
5267
  },
5078
5268
  "lists.indent": {
5079
5269
  input: objectSchema({
@@ -5091,21 +5281,113 @@ var init_schemas = __esm(() => {
5091
5281
  success: listsMutateItemSuccessSchema,
5092
5282
  failure: listsFailureSchemaFor("lists.outdent")
5093
5283
  },
5094
- "lists.restart": {
5284
+ "lists.join": {
5285
+ input: objectSchema({
5286
+ target: listItemAddressSchema,
5287
+ direction: { enum: ["withPrevious", "withNext"] }
5288
+ }, ["target", "direction"]),
5289
+ output: {
5290
+ oneOf: [
5291
+ objectSchema({ success: { const: true }, listId: { type: "string" } }, ["success", "listId"]),
5292
+ listsFailureSchemaFor("lists.join")
5293
+ ]
5294
+ },
5295
+ success: objectSchema({ success: { const: true }, listId: { type: "string" } }, ["success", "listId"]),
5296
+ failure: listsFailureSchemaFor("lists.join")
5297
+ },
5298
+ "lists.canJoin": {
5299
+ input: objectSchema({
5300
+ target: listItemAddressSchema,
5301
+ direction: { enum: ["withPrevious", "withNext"] }
5302
+ }, ["target", "direction"]),
5303
+ output: objectSchema({
5304
+ canJoin: { type: "boolean" },
5305
+ reason: { enum: ["NO_ADJACENT_SEQUENCE", "INCOMPATIBLE_DEFINITIONS", "ALREADY_SAME_SEQUENCE"] },
5306
+ adjacentListId: { type: "string" }
5307
+ }, ["canJoin"])
5308
+ },
5309
+ "lists.separate": {
5310
+ input: objectSchema({
5311
+ target: listItemAddressSchema,
5312
+ copyOverrides: { type: "boolean" }
5313
+ }, ["target"]),
5314
+ output: {
5315
+ oneOf: [
5316
+ objectSchema({ success: { const: true }, listId: { type: "string" }, numId: { type: "integer" } }, [
5317
+ "success",
5318
+ "listId",
5319
+ "numId"
5320
+ ]),
5321
+ listsFailureSchemaFor("lists.separate")
5322
+ ]
5323
+ },
5324
+ success: objectSchema({ success: { const: true }, listId: { type: "string" }, numId: { type: "integer" } }, [
5325
+ "success",
5326
+ "listId",
5327
+ "numId"
5328
+ ]),
5329
+ failure: listsFailureSchemaFor("lists.separate")
5330
+ },
5331
+ "lists.setLevel": {
5332
+ input: objectSchema({
5333
+ target: listItemAddressSchema,
5334
+ level: { type: "integer", minimum: 0, maximum: 8 }
5335
+ }, ["target", "level"]),
5336
+ output: listsMutateItemResultSchemaFor("lists.setLevel"),
5337
+ success: listsMutateItemSuccessSchema,
5338
+ failure: listsFailureSchemaFor("lists.setLevel")
5339
+ },
5340
+ "lists.setValue": {
5341
+ input: objectSchema({
5342
+ target: listItemAddressSchema,
5343
+ value: { type: ["integer", "null"] }
5344
+ }, ["target", "value"]),
5345
+ output: listsMutateItemResultSchemaFor("lists.setValue"),
5346
+ success: listsMutateItemSuccessSchema,
5347
+ failure: listsFailureSchemaFor("lists.setValue")
5348
+ },
5349
+ "lists.continuePrevious": {
5095
5350
  input: objectSchema({
5096
5351
  target: listItemAddressSchema
5097
5352
  }, ["target"]),
5098
- output: listsMutateItemResultSchemaFor("lists.restart"),
5353
+ output: listsMutateItemResultSchemaFor("lists.continuePrevious"),
5099
5354
  success: listsMutateItemSuccessSchema,
5100
- failure: listsFailureSchemaFor("lists.restart")
5355
+ failure: listsFailureSchemaFor("lists.continuePrevious")
5101
5356
  },
5102
- "lists.exit": {
5357
+ "lists.canContinuePrevious": {
5103
5358
  input: objectSchema({
5104
5359
  target: listItemAddressSchema
5105
5360
  }, ["target"]),
5106
- output: listsExitResultSchemaFor("lists.exit"),
5107
- success: listsExitSuccessSchema,
5108
- failure: listsFailureSchemaFor("lists.exit")
5361
+ output: objectSchema({
5362
+ canContinue: { type: "boolean" },
5363
+ reason: { enum: ["NO_PREVIOUS_LIST", "INCOMPATIBLE_DEFINITIONS", "ALREADY_CONTINUOUS"] },
5364
+ previousListId: { type: "string" }
5365
+ }, ["canContinue"])
5366
+ },
5367
+ "lists.setLevelRestart": {
5368
+ input: objectSchema({
5369
+ target: listItemAddressSchema,
5370
+ level: { type: "integer", minimum: 0, maximum: 8 },
5371
+ restartAfterLevel: { type: ["integer", "null"] },
5372
+ scope: { enum: ["definition", "instance"] }
5373
+ }, ["target", "level", "restartAfterLevel"]),
5374
+ output: listsMutateItemResultSchemaFor("lists.setLevelRestart"),
5375
+ success: listsMutateItemSuccessSchema,
5376
+ failure: listsFailureSchemaFor("lists.setLevelRestart")
5377
+ },
5378
+ "lists.convertToText": {
5379
+ input: objectSchema({
5380
+ target: listItemAddressSchema,
5381
+ includeMarker: { type: "boolean" }
5382
+ }, ["target"]),
5383
+ output: {
5384
+ oneOf: [
5385
+ objectSchema({ success: { const: true }, paragraph: ref("ParagraphAddress") }, ["success", "paragraph"]),
5386
+ listsFailureSchemaFor("lists.convertToText")
5387
+ ]
5388
+ },
5389
+ success: objectSchema({ success: { const: true }, paragraph: ref("ParagraphAddress") }, ["success", "paragraph"]),
5390
+ failure: listsFailureSchemaFor("lists.convertToText")
5109
5391
  },
5110
5392
  "comments.create": {
5111
5393
  input: objectSchema({
@@ -6757,10 +7039,6 @@ function executeListsInsert(adapter, input, options) {
6757
7039
  validateListTarget(input, "lists.insert");
6758
7040
  return adapter.insert(input, normalizeMutationOptions(options));
6759
7041
  }
6760
- function executeListsSetType(adapter, input, options) {
6761
- validateListTarget(input, "lists.setType");
6762
- return adapter.setType(input, normalizeMutationOptions(options));
6763
- }
6764
7042
  function executeListsIndent(adapter, input, options) {
6765
7043
  validateListTarget(input, "lists.indent");
6766
7044
  return adapter.indent(input, normalizeMutationOptions(options));
@@ -6769,13 +7047,52 @@ function executeListsOutdent(adapter, input, options) {
6769
7047
  validateListTarget(input, "lists.outdent");
6770
7048
  return adapter.outdent(input, normalizeMutationOptions(options));
6771
7049
  }
6772
- function executeListsRestart(adapter, input, options) {
6773
- validateListTarget(input, "lists.restart");
6774
- return adapter.restart(input, normalizeMutationOptions(options));
7050
+ function executeListsCreate(adapter, input, options) {
7051
+ return adapter.create(input, normalizeMutationOptions(options));
7052
+ }
7053
+ function executeListsAttach(adapter, input, options) {
7054
+ validateListTarget(input, "lists.attach");
7055
+ return adapter.attach(input, normalizeMutationOptions(options));
6775
7056
  }
6776
- function executeListsExit(adapter, input, options) {
6777
- validateListTarget(input, "lists.exit");
6778
- return adapter.exit(input, normalizeMutationOptions(options));
7057
+ function executeListsDetach(adapter, input, options) {
7058
+ validateListTarget(input, "lists.detach");
7059
+ return adapter.detach(input, normalizeMutationOptions(options));
7060
+ }
7061
+ function executeListsJoin(adapter, input, options) {
7062
+ validateListTarget(input, "lists.join");
7063
+ return adapter.join(input, normalizeMutationOptions(options));
7064
+ }
7065
+ function executeListsCanJoin(adapter, input) {
7066
+ validateListTarget(input, "lists.canJoin");
7067
+ return adapter.canJoin(input);
7068
+ }
7069
+ function executeListsSeparate(adapter, input, options) {
7070
+ validateListTarget(input, "lists.separate");
7071
+ return adapter.separate(input, normalizeMutationOptions(options));
7072
+ }
7073
+ function executeListsSetLevel(adapter, input, options) {
7074
+ validateListTarget(input, "lists.setLevel");
7075
+ return adapter.setLevel(input, normalizeMutationOptions(options));
7076
+ }
7077
+ function executeListsSetValue(adapter, input, options) {
7078
+ validateListTarget(input, "lists.setValue");
7079
+ return adapter.setValue(input, normalizeMutationOptions(options));
7080
+ }
7081
+ function executeListsContinuePrevious(adapter, input, options) {
7082
+ validateListTarget(input, "lists.continuePrevious");
7083
+ return adapter.continuePrevious(input, normalizeMutationOptions(options));
7084
+ }
7085
+ function executeListsCanContinuePrevious(adapter, input) {
7086
+ validateListTarget(input, "lists.canContinuePrevious");
7087
+ return adapter.canContinuePrevious(input);
7088
+ }
7089
+ function executeListsSetLevelRestart(adapter, input, options) {
7090
+ validateListTarget(input, "lists.setLevelRestart");
7091
+ return adapter.setLevelRestart(input, normalizeMutationOptions(options));
7092
+ }
7093
+ function executeListsConvertToText(adapter, input, options) {
7094
+ validateListTarget(input, "lists.convertToText");
7095
+ return adapter.convertToText(input, normalizeMutationOptions(options));
6779
7096
  }
6780
7097
  var init_lists = __esm(() => {
6781
7098
  init_errors2();
@@ -7094,11 +7411,20 @@ function buildDispatchTable(api) {
7094
7411
  "lists.list": (input) => api.lists.list(input),
7095
7412
  "lists.get": (input) => api.lists.get(input),
7096
7413
  "lists.insert": (input, options) => api.lists.insert(input, options),
7097
- "lists.setType": (input, options) => api.lists.setType(input, options),
7414
+ "lists.create": (input, options) => api.lists.create(input, options),
7415
+ "lists.attach": (input, options) => api.lists.attach(input, options),
7416
+ "lists.detach": (input, options) => api.lists.detach(input, options),
7098
7417
  "lists.indent": (input, options) => api.lists.indent(input, options),
7099
7418
  "lists.outdent": (input, options) => api.lists.outdent(input, options),
7100
- "lists.restart": (input, options) => api.lists.restart(input, options),
7101
- "lists.exit": (input, options) => api.lists.exit(input, options),
7419
+ "lists.join": (input, options) => api.lists.join(input, options),
7420
+ "lists.canJoin": (input) => api.lists.canJoin(input),
7421
+ "lists.separate": (input, options) => api.lists.separate(input, options),
7422
+ "lists.setLevel": (input, options) => api.lists.setLevel(input, options),
7423
+ "lists.setValue": (input, options) => api.lists.setValue(input, options),
7424
+ "lists.continuePrevious": (input, options) => api.lists.continuePrevious(input, options),
7425
+ "lists.canContinuePrevious": (input) => api.lists.canContinuePrevious(input),
7426
+ "lists.setLevelRestart": (input, options) => api.lists.setLevelRestart(input, options),
7427
+ "lists.convertToText": (input, options) => api.lists.convertToText(input, options),
7102
7428
  "sections.list": (input) => api.sections.list(input),
7103
7429
  "sections.get": (input) => api.sections.get(input),
7104
7430
  "sections.setBreakType": (input, options) => api.sections.setBreakType(input, options),
@@ -7864,8 +8190,14 @@ function createDocumentApi(adapters) {
7864
8190
  insert(input, options) {
7865
8191
  return executeListsInsert(adapters.lists, input, options);
7866
8192
  },
7867
- setType(input, options) {
7868
- return executeListsSetType(adapters.lists, input, options);
8193
+ create(input, options) {
8194
+ return executeListsCreate(adapters.lists, input, options);
8195
+ },
8196
+ attach(input, options) {
8197
+ return executeListsAttach(adapters.lists, input, options);
8198
+ },
8199
+ detach(input, options) {
8200
+ return executeListsDetach(adapters.lists, input, options);
7869
8201
  },
7870
8202
  indent(input, options) {
7871
8203
  return executeListsIndent(adapters.lists, input, options);
@@ -7873,11 +8205,32 @@ function createDocumentApi(adapters) {
7873
8205
  outdent(input, options) {
7874
8206
  return executeListsOutdent(adapters.lists, input, options);
7875
8207
  },
7876
- restart(input, options) {
7877
- return executeListsRestart(adapters.lists, input, options);
8208
+ join(input, options) {
8209
+ return executeListsJoin(adapters.lists, input, options);
8210
+ },
8211
+ canJoin(input) {
8212
+ return executeListsCanJoin(adapters.lists, input);
8213
+ },
8214
+ separate(input, options) {
8215
+ return executeListsSeparate(adapters.lists, input, options);
8216
+ },
8217
+ setLevel(input, options) {
8218
+ return executeListsSetLevel(adapters.lists, input, options);
8219
+ },
8220
+ setValue(input, options) {
8221
+ return executeListsSetValue(adapters.lists, input, options);
8222
+ },
8223
+ continuePrevious(input, options) {
8224
+ return executeListsContinuePrevious(adapters.lists, input, options);
7878
8225
  },
7879
- exit(input, options) {
7880
- return executeListsExit(adapters.lists, input, options);
8226
+ canContinuePrevious(input) {
8227
+ return executeListsCanContinuePrevious(adapters.lists, input);
8228
+ },
8229
+ setLevelRestart(input, options) {
8230
+ return executeListsSetLevelRestart(adapters.lists, input, options);
8231
+ },
8232
+ convertToText(input, options) {
8233
+ return executeListsConvertToText(adapters.lists, input, options);
7881
8234
  }
7882
8235
  },
7883
8236
  sections: {
@@ -8248,17 +8601,28 @@ async function pathExists(path) {
8248
8601
  var init_guards = () => {};
8249
8602
 
8250
8603
  // src/lib/context.ts
8604
+ import { AsyncLocalStorage } from "node:async_hooks";
8251
8605
  import { copyFile, mkdir, open, readdir, readFile as readFile2, rename, rm, stat, unlink, writeFile } from "node:fs/promises";
8252
8606
  import { createHash } from "node:crypto";
8253
8607
  import { homedir, hostname } from "node:os";
8254
8608
  import { join, resolve } from "node:path";
8255
8609
  function getStateRoot() {
8610
+ const scopedOverride = STATE_DIR_OVERRIDE_STORAGE.getStore();
8611
+ if (scopedOverride && scopedOverride.length > 0) {
8612
+ return scopedOverride;
8613
+ }
8256
8614
  const override = process.env.SUPERDOC_CLI_STATE_DIR;
8257
8615
  if (override && override.length > 0) {
8258
8616
  return resolve(override);
8259
8617
  }
8260
8618
  return join(homedir(), ".superdoc-cli", "state", CONTEXT_VERSION);
8261
8619
  }
8620
+ async function withStateDirOverride(stateDir, operation) {
8621
+ if (stateDir == null || stateDir.length === 0) {
8622
+ return operation();
8623
+ }
8624
+ return STATE_DIR_OVERRIDE_STORAGE.run(resolve(stateDir), operation);
8625
+ }
8262
8626
  function getContextPaths(contextId) {
8263
8627
  const normalizedContextId = validateSessionId(contextId, "session id");
8264
8628
  const stateRoot = getStateRoot();
@@ -8776,11 +9140,12 @@ function createInitialContextMetadata(io, paths, contextId, input) {
8776
9140
  sourceSnapshot: input.sourceSnapshot
8777
9141
  };
8778
9142
  }
8779
- var CONTEXT_VERSION = "v1", ACTIVE_SESSION_FILENAME = "active-session", DEFAULT_LOCK_TIMEOUT_MS = 5000, LOCK_RETRY_INTERVAL_MS = 50;
9143
+ var CONTEXT_VERSION = "v1", ACTIVE_SESSION_FILENAME = "active-session", DEFAULT_LOCK_TIMEOUT_MS = 5000, LOCK_RETRY_INTERVAL_MS = 50, STATE_DIR_OVERRIDE_STORAGE;
8780
9144
  var init_context = __esm(() => {
8781
9145
  init_errors();
8782
9146
  init_guards();
8783
9147
  init_session();
9148
+ STATE_DIR_OVERRIDE_STORAGE = new AsyncLocalStorage;
8784
9149
  });
8785
9150
 
8786
9151
  // src/cli/operation-hints.ts
@@ -8838,11 +9203,20 @@ var init_operation_hints = __esm(() => {
8838
9203
  "lists.list": "listed items",
8839
9204
  "lists.get": "resolved list item",
8840
9205
  "lists.insert": "inserted list item",
8841
- "lists.setType": "set list type",
8842
9206
  "lists.indent": "indented list item",
8843
9207
  "lists.outdent": "outdented list item",
8844
- "lists.restart": "restarted list numbering",
8845
- "lists.exit": "exited list item",
9208
+ "lists.create": "created list",
9209
+ "lists.attach": "attached to list",
9210
+ "lists.detach": "detached from list",
9211
+ "lists.join": "joined lists",
9212
+ "lists.canJoin": "checked join feasibility",
9213
+ "lists.separate": "separated list",
9214
+ "lists.setLevel": "set list level",
9215
+ "lists.setValue": "set list value",
9216
+ "lists.continuePrevious": "continued previous list",
9217
+ "lists.canContinuePrevious": "checked continue feasibility",
9218
+ "lists.setLevelRestart": "set level restart",
9219
+ "lists.convertToText": "converted list to text",
8846
9220
  "comments.create": "created comment",
8847
9221
  "comments.patch": "patched comment",
8848
9222
  "comments.delete": "deleted comment",
@@ -8929,11 +9303,20 @@ var init_operation_hints = __esm(() => {
8929
9303
  "lists.list": "listResult",
8930
9304
  "lists.get": "listItemInfo",
8931
9305
  "lists.insert": "listsMutationResult",
8932
- "lists.setType": "listsMutationResult",
8933
9306
  "lists.indent": "listsMutationResult",
8934
9307
  "lists.outdent": "listsMutationResult",
8935
- "lists.restart": "listsMutationResult",
8936
- "lists.exit": "listsMutationResult",
9308
+ "lists.create": "listsMutationResult",
9309
+ "lists.attach": "listsMutationResult",
9310
+ "lists.detach": "listsMutationResult",
9311
+ "lists.join": "listsMutationResult",
9312
+ "lists.canJoin": "plain",
9313
+ "lists.separate": "listsMutationResult",
9314
+ "lists.setLevel": "listsMutationResult",
9315
+ "lists.setValue": "listsMutationResult",
9316
+ "lists.continuePrevious": "listsMutationResult",
9317
+ "lists.canContinuePrevious": "plain",
9318
+ "lists.setLevelRestart": "listsMutationResult",
9319
+ "lists.convertToText": "listsMutationResult",
8937
9320
  "comments.create": "commentReceipt",
8938
9321
  "comments.patch": "commentReceipt",
8939
9322
  "comments.delete": "commentReceipt",
@@ -9020,11 +9403,20 @@ var init_operation_hints = __esm(() => {
9020
9403
  "lists.list": "result",
9021
9404
  "lists.get": "item",
9022
9405
  "lists.insert": "result",
9023
- "lists.setType": "result",
9024
9406
  "lists.indent": "result",
9025
9407
  "lists.outdent": "result",
9026
- "lists.restart": "result",
9027
- "lists.exit": "result",
9408
+ "lists.create": "result",
9409
+ "lists.attach": "result",
9410
+ "lists.detach": "result",
9411
+ "lists.join": "result",
9412
+ "lists.canJoin": "result",
9413
+ "lists.separate": "result",
9414
+ "lists.setLevel": "result",
9415
+ "lists.setValue": "result",
9416
+ "lists.continuePrevious": "result",
9417
+ "lists.canContinuePrevious": "result",
9418
+ "lists.setLevelRestart": "result",
9419
+ "lists.convertToText": "result",
9028
9420
  "comments.create": "receipt",
9029
9421
  "comments.patch": "receipt",
9030
9422
  "comments.delete": "receipt",
@@ -9118,11 +9510,20 @@ var init_operation_hints = __esm(() => {
9118
9510
  "lists.list": "lists",
9119
9511
  "lists.get": "lists",
9120
9512
  "lists.insert": "lists",
9121
- "lists.setType": "lists",
9122
9513
  "lists.indent": "lists",
9123
9514
  "lists.outdent": "lists",
9124
- "lists.restart": "lists",
9125
- "lists.exit": "lists",
9515
+ "lists.create": "lists",
9516
+ "lists.attach": "lists",
9517
+ "lists.detach": "lists",
9518
+ "lists.join": "lists",
9519
+ "lists.canJoin": "lists",
9520
+ "lists.separate": "lists",
9521
+ "lists.setLevel": "lists",
9522
+ "lists.setValue": "lists",
9523
+ "lists.continuePrevious": "lists",
9524
+ "lists.canContinuePrevious": "lists",
9525
+ "lists.setLevelRestart": "lists",
9526
+ "lists.convertToText": "lists",
9126
9527
  "comments.create": "comments",
9127
9528
  "comments.patch": "comments",
9128
9529
  "comments.delete": "comments",
@@ -12156,11 +12557,18 @@ var init_capabilities_adapter = __esm(() => {
12156
12557
  "create.paragraph": ["insertParagraphAt"],
12157
12558
  "create.heading": ["insertHeadingAt"],
12158
12559
  "lists.insert": ["insertListItemAt"],
12159
- "lists.setType": ["setListTypeAt"],
12160
- "lists.indent": ["setTextSelection", "increaseListIndent"],
12161
- "lists.outdent": ["setTextSelection", "decreaseListIndent"],
12162
- "lists.restart": ["setTextSelection", "restartNumbering"],
12163
- "lists.exit": ["exitListItemAt"],
12560
+ "lists.indent": [],
12561
+ "lists.outdent": [],
12562
+ "lists.create": [],
12563
+ "lists.attach": [],
12564
+ "lists.detach": [],
12565
+ "lists.join": [],
12566
+ "lists.separate": [],
12567
+ "lists.setLevel": [],
12568
+ "lists.setValue": [],
12569
+ "lists.continuePrevious": [],
12570
+ "lists.setLevelRestart": [],
12571
+ "lists.convertToText": [],
12164
12572
  "blocks.delete": ["deleteBlockNodeById"],
12165
12573
  "comments.create": ["addComment", "setTextSelection", "addCommentReply"],
12166
12574
  "comments.patch": ["editComment", "moveComment", "resolveComment", "setCommentInternal"],
@@ -67900,6 +68308,47 @@ var init_footnotesExporter = __esm(() => {
67900
68308
  init_relationship_helpers();
67901
68309
  });
67902
68310
 
68311
+ // ../../packages/super-editor/src/core/super-converter/export-helpers/strip-orphaned-numbering.js
68312
+ function collectReferencedNumIds(convertedXml) {
68313
+ const numIds = new Set;
68314
+ function walkElements(elements) {
68315
+ if (!Array.isArray(elements))
68316
+ return;
68317
+ for (const el of elements) {
68318
+ if (el.name === "w:numId" && el.attributes?.["w:val"] != null) {
68319
+ numIds.add(Number(el.attributes["w:val"]));
68320
+ }
68321
+ if (el.elements)
68322
+ walkElements(el.elements);
68323
+ }
68324
+ }
68325
+ for (const [path2, xml] of Object.entries(convertedXml)) {
68326
+ if (path2.startsWith("word/") && path2 !== "word/numbering.xml" && xml?.elements) {
68327
+ walkElements(xml.elements);
68328
+ }
68329
+ }
68330
+ return numIds;
68331
+ }
68332
+ function getAbstractNumIdFromDef(numDef) {
68333
+ const abstractEl = numDef.elements?.find((el) => el.name === "w:abstractNumId");
68334
+ if (abstractEl?.attributes?.["w:val"] != null) {
68335
+ return Number(abstractEl.attributes["w:val"]);
68336
+ }
68337
+ return;
68338
+ }
68339
+ function filterOrphanedNumberingDefinitions(numbering, referencedNumIds) {
68340
+ const liveDefinitions = Object.values(numbering.definitions).filter((def) => referencedNumIds.has(Number(def.attributes?.["w:numId"])));
68341
+ const referencedAbstractIds = new Set;
68342
+ for (const def of liveDefinitions) {
68343
+ const abstractId = getAbstractNumIdFromDef(def);
68344
+ if (abstractId != null) {
68345
+ referencedAbstractIds.add(abstractId);
68346
+ }
68347
+ }
68348
+ const liveAbstracts = Object.values(numbering.abstracts).filter((abs2) => referencedAbstractIds.has(Number(abs2.attributes?.["w:abstractNumId"])));
68349
+ return { liveAbstracts, liveDefinitions };
68350
+ }
68351
+
67903
68352
  // ../../packages/super-editor/src/core/super-converter/SuperConverter.js
67904
68353
  function generateCustomXml() {
67905
68354
  return DEFAULT_CUSTOM_XML;
@@ -68690,13 +69139,12 @@ var init_SuperConverter = __esm(() => {
68690
69139
  #exportNumberingFile() {
68691
69140
  const numberingPath = "word/numbering.xml";
68692
69141
  let numberingXml = this.convertedXml[numberingPath];
68693
- const newNumbering = this.numbering;
68694
69142
  if (!numberingXml)
68695
69143
  numberingXml = baseNumbering;
68696
69144
  const currentNumberingXml = numberingXml.elements[0];
68697
- const newAbstracts = Object.values(newNumbering.abstracts).map((entry) => entry);
68698
- const newNumDefs = Object.values(newNumbering.definitions).map((entry) => entry);
68699
- currentNumberingXml.elements = [...newAbstracts, ...newNumDefs];
69145
+ const referencedNumIds = collectReferencedNumIds(this.convertedXml);
69146
+ const { liveAbstracts, liveDefinitions } = filterOrphanedNumberingDefinitions(this.numbering, referencedNumIds);
69147
+ currentNumberingXml.elements = [...liveAbstracts, ...liveDefinitions];
68700
69148
  this.convertedXml[numberingPath] = numberingXml;
68701
69149
  }
68702
69150
  #prepareCommentsXmlFilesForExport({ defs, exportType, commentsWithParaIds }) {
@@ -69816,7 +70264,7 @@ var generateNewListDefinition = ({ numId, listType, level, start, text: text5, f
69816
70264
  "w:abstractNumId": String(newAbstractId)
69817
70265
  }
69818
70266
  }));
69819
- if (level && start && text5 && fmt) {
70267
+ if (level != null && start != null && text5 != null && fmt != null) {
69820
70268
  if (newNumbering.definitions[numId]) {
69821
70269
  const abstractId = newNumbering.definitions[numId]?.elements[0]?.attributes["w:val"];
69822
70270
  newAbstractId = abstractId;
@@ -70094,6 +70542,153 @@ var generateNewListDefinition = ({ numId, listType, level, start, text: text5, f
70094
70542
  return true;
70095
70543
  }, replaceListWithNode = ({ tr, from: from3, to, newNode }) => {
70096
70544
  tr.replaceWith(from3, to, newNode);
70545
+ }, setLvlOverride = (editor, numId, ilvl, overrides) => {
70546
+ const numbering = editor.converter.numbering;
70547
+ const numDef = numbering.definitions[numId];
70548
+ if (!numDef)
70549
+ return;
70550
+ const ilvlStr = String(ilvl);
70551
+ if (!numDef.elements)
70552
+ numDef.elements = [];
70553
+ let overrideEl = numDef.elements.find((el) => el.name === "w:lvlOverride" && el.attributes?.["w:ilvl"] === ilvlStr);
70554
+ if (!overrideEl) {
70555
+ overrideEl = {
70556
+ type: "element",
70557
+ name: "w:lvlOverride",
70558
+ attributes: { "w:ilvl": ilvlStr },
70559
+ elements: []
70560
+ };
70561
+ numDef.elements.push(overrideEl);
70562
+ }
70563
+ if (!overrideEl.elements)
70564
+ overrideEl.elements = [];
70565
+ if (overrides.startOverride != null) {
70566
+ const startEl = overrideEl.elements.find((el) => el.name === "w:startOverride");
70567
+ if (startEl) {
70568
+ startEl.attributes["w:val"] = String(overrides.startOverride);
70569
+ } else {
70570
+ overrideEl.elements.push({
70571
+ type: "element",
70572
+ name: "w:startOverride",
70573
+ attributes: { "w:val": String(overrides.startOverride) }
70574
+ });
70575
+ }
70576
+ }
70577
+ if ("lvlRestart" in overrides) {
70578
+ let lvlEl = overrideEl.elements.find((el) => el.name === "w:lvl");
70579
+ if (!lvlEl) {
70580
+ lvlEl = {
70581
+ type: "element",
70582
+ name: "w:lvl",
70583
+ attributes: { "w:ilvl": ilvlStr },
70584
+ elements: []
70585
+ };
70586
+ overrideEl.elements.push(lvlEl);
70587
+ }
70588
+ if (!lvlEl.elements)
70589
+ lvlEl.elements = [];
70590
+ if (overrides.lvlRestart === null) {
70591
+ lvlEl.elements = lvlEl.elements.filter((el) => el.name !== "w:lvlRestart");
70592
+ } else {
70593
+ const restartEl = lvlEl.elements.find((el) => el.name === "w:lvlRestart");
70594
+ if (restartEl) {
70595
+ restartEl.attributes["w:val"] = String(overrides.lvlRestart);
70596
+ } else {
70597
+ lvlEl.elements.push({
70598
+ type: "element",
70599
+ name: "w:lvlRestart",
70600
+ attributes: { "w:val": String(overrides.lvlRestart) }
70601
+ });
70602
+ }
70603
+ }
70604
+ }
70605
+ numbering.definitions[numId] = numDef;
70606
+ editor.converter.numbering = { ...numbering };
70607
+ syncTranslatedDefinition(editor, numId, numDef);
70608
+ emitDefinitionChange(editor, numDef);
70609
+ }, removeLvlOverride = (editor, numId, ilvl) => {
70610
+ const numbering = editor.converter.numbering;
70611
+ const numDef = numbering.definitions[numId];
70612
+ if (!numDef?.elements)
70613
+ return;
70614
+ const ilvlStr = String(ilvl);
70615
+ const idx = numDef.elements.findIndex((el) => el.name === "w:lvlOverride" && el.attributes?.["w:ilvl"] === ilvlStr);
70616
+ if (idx === -1)
70617
+ return;
70618
+ numDef.elements.splice(idx, 1);
70619
+ numbering.definitions[numId] = numDef;
70620
+ editor.converter.numbering = { ...numbering };
70621
+ syncTranslatedDefinition(editor, numId, numDef);
70622
+ emitDefinitionChange(editor, numDef);
70623
+ }, syncTranslatedDefinition = (editor, numId, rawNumDef) => {
70624
+ const translated = { ...editor.converter.translatedNumbering || {} };
70625
+ if (!translated.definitions)
70626
+ translated.definitions = {};
70627
+ translated.definitions[numId] = translator195.encode({ nodes: [rawNumDef] });
70628
+ editor.converter.translatedNumbering = translated;
70629
+ }, emitDefinitionChange = (editor, numDef) => {
70630
+ editor.emit("list-definitions-change", {
70631
+ change: { numDef, editor },
70632
+ numbering: editor.converter.numbering,
70633
+ editor
70634
+ });
70635
+ }, createNumDefinition = (editor, abstractNumId, options = {}) => {
70636
+ const numId = getNewListId(editor, "definitions");
70637
+ const numDef = getBasicNumIdTag(numId, abstractNumId);
70638
+ if (options.copyOverridesFrom != null) {
70639
+ const sourceNumDef = editor.converter.numbering.definitions[options.copyOverridesFrom];
70640
+ if (sourceNumDef?.elements) {
70641
+ const overrideEls = sourceNumDef.elements.filter((el) => el.name === "w:lvlOverride");
70642
+ if (overrideEls.length > 0) {
70643
+ numDef.elements = [...numDef.elements, ...JSON.parse(JSON.stringify(overrideEls))];
70644
+ }
70645
+ }
70646
+ }
70647
+ const numbering = editor.converter.numbering;
70648
+ numbering.definitions[numId] = numDef;
70649
+ editor.converter.numbering = { ...numbering };
70650
+ syncTranslatedDefinition(editor, numId, numDef);
70651
+ emitDefinitionChange(editor, numDef);
70652
+ return { numId, numDef };
70653
+ }, setLvlRestartOnAbstract = (editor, abstractNumId, ilvl, restartAfterLevel) => {
70654
+ const numbering = editor.converter.numbering;
70655
+ const abstract = numbering.abstracts[abstractNumId];
70656
+ if (!abstract?.elements)
70657
+ return;
70658
+ const ilvlStr = String(ilvl);
70659
+ const lvlEl = abstract.elements.find((el) => el.name === "w:lvl" && el.attributes?.["w:ilvl"] === ilvlStr);
70660
+ if (!lvlEl)
70661
+ return;
70662
+ if (!lvlEl.elements)
70663
+ lvlEl.elements = [];
70664
+ if (restartAfterLevel === null) {
70665
+ lvlEl.elements = lvlEl.elements.filter((el) => el.name !== "w:lvlRestart");
70666
+ } else {
70667
+ const restartEl = lvlEl.elements.find((el) => el.name === "w:lvlRestart");
70668
+ if (restartEl) {
70669
+ restartEl.attributes["w:val"] = String(restartAfterLevel);
70670
+ } else {
70671
+ lvlEl.elements.push({
70672
+ type: "element",
70673
+ name: "w:lvlRestart",
70674
+ attributes: { "w:val": String(restartAfterLevel) }
70675
+ });
70676
+ }
70677
+ }
70678
+ numbering.abstracts[abstractNumId] = abstract;
70679
+ editor.converter.numbering = { ...numbering };
70680
+ const translated = { ...editor.converter.translatedNumbering || {} };
70681
+ if (!translated.abstracts)
70682
+ translated.abstracts = {};
70683
+ translated.abstracts[abstractNumId] = translator181.encode({ nodes: [abstract] });
70684
+ editor.converter.translatedNumbering = translated;
70685
+ const definitions = numbering.definitions || {};
70686
+ for (const [, numDef] of Object.entries(definitions)) {
70687
+ const absId = numDef?.elements?.find((el) => el.name === "w:abstractNumId")?.attributes?.["w:val"];
70688
+ if (absId != null && Number(absId) === abstractNumId) {
70689
+ emitDefinitionChange(editor, numDef);
70690
+ }
70691
+ }
70097
70692
  }, ListHelpers;
70098
70693
  var init_list_numbering_helpers = __esm(() => {
70099
70694
  init_listImporter();
@@ -70111,6 +70706,10 @@ var init_list_numbering_helpers = __esm(() => {
70111
70706
  getNewListId,
70112
70707
  hasListDefinition,
70113
70708
  removeListDefinitions,
70709
+ setLvlOverride,
70710
+ removeLvlOverride,
70711
+ createNumDefinition,
70712
+ setLvlRestartOnAbstract,
70114
70713
  createNewList,
70115
70714
  createSchemaOrderedListNode,
70116
70715
  createListItemNodeJSON,
@@ -73205,6 +73804,220 @@ var init_blocks_wrappers = __esm(() => {
73205
73804
  REJECTED_NODE_TYPES = new Set(["tableRow", "tableCell"]);
73206
73805
  });
73207
73806
 
73807
+ // ../../packages/super-editor/src/document-api-adapters/helpers/list-sequence-helpers.ts
73808
+ function resolveBlock(editor, nodeId) {
73809
+ const index2 = getBlockIndex(editor);
73810
+ const matches2 = index2.candidates.filter((c) => c.nodeId === nodeId && (c.nodeType === "paragraph" || c.nodeType === "listItem"));
73811
+ if (matches2.length === 0) {
73812
+ throw new DocumentApiAdapterError("TARGET_NOT_FOUND", "Block target was not found.", { nodeId });
73813
+ }
73814
+ if (matches2.length > 1) {
73815
+ throw new DocumentApiAdapterError("INVALID_TARGET", "Block target id is ambiguous.", {
73816
+ nodeId,
73817
+ count: matches2.length
73818
+ });
73819
+ }
73820
+ return matches2[0];
73821
+ }
73822
+ function resolveBlocksInRange(editor, fromId, toId2) {
73823
+ const from3 = resolveBlock(editor, fromId);
73824
+ const to = resolveBlock(editor, toId2);
73825
+ if (from3.pos > to.pos) {
73826
+ throw new DocumentApiAdapterError("INVALID_TARGET", 'Block range "from" must precede "to" in document order.', {
73827
+ from: fromId,
73828
+ to: toId2
73829
+ });
73830
+ }
73831
+ const index2 = getBlockIndex(editor);
73832
+ return index2.candidates.filter((c) => (c.nodeType === "paragraph" || c.nodeType === "listItem") && c.pos >= from3.pos && c.pos <= to.pos);
73833
+ }
73834
+ function getAbstractNumId(editor, numId) {
73835
+ const converter = editor;
73836
+ const definitions = converter.converter?.numbering?.definitions;
73837
+ if (!definitions)
73838
+ return;
73839
+ const numDef = definitions[numId];
73840
+ if (!numDef?.elements)
73841
+ return;
73842
+ const abstractEl = numDef.elements.find((el) => el.name === "w:abstractNumId");
73843
+ const val = abstractEl?.attributes?.["w:val"];
73844
+ return val != null ? Number(val) : undefined;
73845
+ }
73846
+ function getAllListItemProjections(editor) {
73847
+ const index2 = getBlockIndex(editor);
73848
+ return index2.candidates.filter((c) => c.nodeType === "listItem").map((c) => projectListItemCandidate(editor, c));
73849
+ }
73850
+ function getContiguousSequence(editor, target) {
73851
+ if (target.numId == null)
73852
+ return [target];
73853
+ const allItems = getAllListItemProjections(editor);
73854
+ const targetIdx = allItems.findIndex((item) => item.address.nodeId === target.address.nodeId);
73855
+ if (targetIdx === -1)
73856
+ return [target];
73857
+ const numId = target.numId;
73858
+ let startIdx = targetIdx;
73859
+ for (let i = targetIdx - 1;i >= 0; i--) {
73860
+ if (allItems[i].numId !== numId)
73861
+ break;
73862
+ startIdx = i;
73863
+ }
73864
+ let endIdx = targetIdx;
73865
+ for (let i = targetIdx + 1;i < allItems.length; i++) {
73866
+ if (allItems[i].numId !== numId)
73867
+ break;
73868
+ endIdx = i;
73869
+ }
73870
+ return allItems.slice(startIdx, endIdx + 1);
73871
+ }
73872
+ function getSequenceFromTarget(editor, target) {
73873
+ const sequence = getContiguousSequence(editor, target);
73874
+ const targetIdx = sequence.findIndex((item) => item.address.nodeId === target.address.nodeId);
73875
+ return sequence.slice(targetIdx);
73876
+ }
73877
+ function isFirstInSequence(editor, target) {
73878
+ const sequence = getContiguousSequence(editor, target);
73879
+ return sequence.length > 0 && sequence[0].address.nodeId === target.address.nodeId;
73880
+ }
73881
+ function computeSequenceId(editor, projection) {
73882
+ if (projection.numId == null)
73883
+ return "";
73884
+ const sequence = getContiguousSequence(editor, projection);
73885
+ const anchor = sequence[0]?.address.nodeId ?? projection.address.nodeId;
73886
+ return `${projection.numId}:${anchor}`;
73887
+ }
73888
+ function computeSequenceIdMap(items) {
73889
+ const map5 = new Map;
73890
+ let currentNumId;
73891
+ let currentAnchor;
73892
+ for (const item of items) {
73893
+ if (item.numId == null) {
73894
+ map5.set(item.address.nodeId, "");
73895
+ currentNumId = undefined;
73896
+ currentAnchor = undefined;
73897
+ continue;
73898
+ }
73899
+ if (item.numId !== currentNumId) {
73900
+ currentNumId = item.numId;
73901
+ currentAnchor = item.address.nodeId;
73902
+ }
73903
+ map5.set(item.address.nodeId, `${currentNumId}:${currentAnchor}`);
73904
+ }
73905
+ return map5;
73906
+ }
73907
+ function findAdjacentSequence(editor, target, direction) {
73908
+ if (target.numId == null)
73909
+ return null;
73910
+ const allItems = getAllListItemProjections(editor);
73911
+ const sequence = getContiguousSequence(editor, target);
73912
+ if (direction === "withNext") {
73913
+ const lastInSequence = sequence[sequence.length - 1];
73914
+ const lastIdx = allItems.findIndex((item) => item.address.nodeId === lastInSequence.address.nodeId);
73915
+ for (let i = lastIdx + 1;i < allItems.length; i++) {
73916
+ const item = allItems[i];
73917
+ if (item.numId != null) {
73918
+ const adjSequence = getContiguousSequence(editor, item);
73919
+ return {
73920
+ sequence: adjSequence,
73921
+ numId: item.numId,
73922
+ abstractNumId: getAbstractNumId(editor, item.numId)
73923
+ };
73924
+ }
73925
+ }
73926
+ } else {
73927
+ const firstInSequence = sequence[0];
73928
+ const firstIdx = allItems.findIndex((item) => item.address.nodeId === firstInSequence.address.nodeId);
73929
+ for (let i = firstIdx - 1;i >= 0; i--) {
73930
+ const item = allItems[i];
73931
+ if (item.numId != null) {
73932
+ const adjSequence = getContiguousSequence(editor, item);
73933
+ return {
73934
+ sequence: adjSequence,
73935
+ numId: item.numId,
73936
+ abstractNumId: getAbstractNumId(editor, item.numId)
73937
+ };
73938
+ }
73939
+ }
73940
+ }
73941
+ return null;
73942
+ }
73943
+ function findPreviousCompatibleSequence(editor, target) {
73944
+ if (target.numId == null)
73945
+ return null;
73946
+ const targetAbstractId = getAbstractNumId(editor, target.numId);
73947
+ if (targetAbstractId == null)
73948
+ return null;
73949
+ const allItems = getAllListItemProjections(editor);
73950
+ const sequence = getContiguousSequence(editor, target);
73951
+ const firstInSequence = sequence[0];
73952
+ const firstIdx = allItems.findIndex((item) => item.address.nodeId === firstInSequence.address.nodeId);
73953
+ for (let i = firstIdx - 1;i >= 0; i--) {
73954
+ const item = allItems[i];
73955
+ if (item.numId == null)
73956
+ continue;
73957
+ const itemAbstractId = getAbstractNumId(editor, item.numId);
73958
+ if (itemAbstractId === targetAbstractId && item.numId !== target.numId) {
73959
+ return {
73960
+ sequence: getContiguousSequence(editor, item),
73961
+ numId: item.numId
73962
+ };
73963
+ }
73964
+ }
73965
+ return null;
73966
+ }
73967
+ function evaluateCanJoin(editor, target, direction) {
73968
+ const adjacent = findAdjacentSequence(editor, target, direction);
73969
+ if (!adjacent) {
73970
+ return { canJoin: false, reason: "NO_ADJACENT_SEQUENCE" };
73971
+ }
73972
+ if (adjacent.numId === target.numId) {
73973
+ return { canJoin: false, reason: "ALREADY_SAME_SEQUENCE" };
73974
+ }
73975
+ const targetAbstractId = target.numId != null ? getAbstractNumId(editor, target.numId) : undefined;
73976
+ if (targetAbstractId == null || adjacent.abstractNumId == null || targetAbstractId !== adjacent.abstractNumId) {
73977
+ return { canJoin: false, reason: "INCOMPATIBLE_DEFINITIONS" };
73978
+ }
73979
+ const adjacentAnchor = adjacent.sequence[0]?.address.nodeId ?? "";
73980
+ return { canJoin: true, adjacentListId: `${adjacent.numId}:${adjacentAnchor}` };
73981
+ }
73982
+ function evaluateCanContinuePrevious(editor, target) {
73983
+ if (target.numId == null) {
73984
+ return { canContinue: false, reason: "NO_PREVIOUS_LIST" };
73985
+ }
73986
+ const targetAbstractId = getAbstractNumId(editor, target.numId);
73987
+ if (targetAbstractId == null) {
73988
+ return { canContinue: false, reason: "NO_PREVIOUS_LIST" };
73989
+ }
73990
+ const allItems = getAllListItemProjections(editor);
73991
+ const sequence = getContiguousSequence(editor, target);
73992
+ const firstInSequence = sequence[0];
73993
+ const firstIdx = allItems.findIndex((item) => item.address.nodeId === firstInSequence.address.nodeId);
73994
+ let foundAnyPrevious = false;
73995
+ for (let i = firstIdx - 1;i >= 0; i--) {
73996
+ const item = allItems[i];
73997
+ if (item.numId == null)
73998
+ continue;
73999
+ foundAnyPrevious = true;
74000
+ const itemAbstractId = getAbstractNumId(editor, item.numId);
74001
+ if (itemAbstractId !== targetAbstractId)
74002
+ continue;
74003
+ if (item.numId === target.numId) {
74004
+ return { canContinue: false, reason: "ALREADY_CONTINUOUS" };
74005
+ }
74006
+ const prevSequence = getContiguousSequence(editor, item);
74007
+ const prevAnchor = prevSequence[0]?.address.nodeId ?? item.address.nodeId;
74008
+ return { canContinue: true, previousListId: `${item.numId}:${prevAnchor}` };
74009
+ }
74010
+ if (!foundAnyPrevious) {
74011
+ return { canContinue: false, reason: "NO_PREVIOUS_LIST" };
74012
+ }
74013
+ return { canContinue: false, reason: "INCOMPATIBLE_DEFINITIONS" };
74014
+ }
74015
+ var init_list_sequence_helpers = __esm(() => {
74016
+ init_list_item_resolver();
74017
+ init_index_cache();
74018
+ init_errors3();
74019
+ });
74020
+
73208
74021
  // ../../packages/super-editor/src/document-api-adapters/helpers/list-item-resolver.ts
73209
74022
  function toPath(value) {
73210
74023
  if (!Array.isArray(value))
@@ -73270,9 +74083,10 @@ function projectListItemCandidate(editor, candidate) {
73270
74083
  text: getListText(candidate)
73271
74084
  };
73272
74085
  }
73273
- function listItemProjectionToInfo(projection) {
74086
+ function listItemProjectionToInfo(projection, listId) {
73274
74087
  return {
73275
74088
  address: projection.address,
74089
+ listId,
73276
74090
  marker: projection.marker,
73277
74091
  ordinal: projection.ordinal,
73278
74092
  path: projection.path,
@@ -73317,9 +74131,6 @@ function isWithinScope(candidate, scope) {
73317
74131
  return true;
73318
74132
  return candidate.pos >= scope.start && candidate.end <= scope.end;
73319
74133
  }
73320
- function listItemCandidatesInScope(index2, scope) {
73321
- return index2.candidates.filter((candidate) => candidate.nodeType === "listItem" && isWithinScope(candidate, scope));
73322
- }
73323
74134
  function listListItems(editor, query2) {
73324
74135
  if (query2?.within && query2.within.kind !== "block") {
73325
74136
  throw new DocumentApiAdapterError("INVALID_TARGET", "lists.list only supports block within scopes.", {
@@ -73329,25 +74140,28 @@ function listListItems(editor, query2) {
73329
74140
  validatePaginationInput(query2?.offset, query2?.limit);
73330
74141
  const index2 = getBlockIndex(editor);
73331
74142
  const scope = resolveBlockScopeRange(index2, query2?.within);
73332
- const candidates = listItemCandidatesInScope(index2, scope);
74143
+ const allCandidates = index2.candidates.filter((candidate) => candidate.nodeType === "listItem");
74144
+ const allProjections = allCandidates.map((candidate) => projectListItemCandidate(editor, candidate));
74145
+ const projections = allProjections.filter((projection) => isWithinScope(projection.candidate, scope));
73333
74146
  const safeOffset = query2?.offset ?? 0;
73334
74147
  const safeLimit = query2?.limit ?? Number.POSITIVE_INFINITY;
73335
74148
  const pageEnd = safeOffset + safeLimit;
73336
74149
  const evaluatedRevision = getRevision(editor);
74150
+ const sequenceIds = computeSequenceIdMap(allProjections);
73337
74151
  let total = 0;
73338
74152
  const items = [];
73339
- for (const candidate of candidates) {
73340
- const projection = projectListItemCandidate(editor, candidate);
74153
+ for (const projection of projections) {
73341
74154
  if (!matchesListQuery(projection, query2))
73342
74155
  continue;
73343
74156
  const currentIndex = total;
73344
74157
  total += 1;
73345
74158
  if (currentIndex < safeOffset || currentIndex >= pageEnd)
73346
74159
  continue;
73347
- const info = listItemProjectionToInfo(projection);
74160
+ const listId = sequenceIds.get(projection.address.nodeId) ?? "";
74161
+ const info = listItemProjectionToInfo(projection, listId);
73348
74162
  const handle2 = buildResolvedHandle(info.address.nodeId, "stable", "list");
73349
74163
  const { address: address2, marker, ordinal, path: path2, level, kind, text: text5 } = info;
73350
- items.push(buildDiscoveryItem(info.address.nodeId, handle2, { address: address2, marker, ordinal, path: path2, level, kind, text: text5 }));
74164
+ items.push(buildDiscoveryItem(info.address.nodeId, handle2, { address: address2, listId, marker, ordinal, path: path2, level, kind, text: text5 }));
73351
74165
  }
73352
74166
  return buildDiscoveryResult({
73353
74167
  evaluatedRevision,
@@ -73379,12 +74193,24 @@ var init_list_item_resolver = __esm(() => {
73379
74193
  init_revision_tracker();
73380
74194
  init_index_cache();
73381
74195
  init_adapter_utils();
74196
+ init_list_sequence_helpers();
73382
74197
  });
73383
74198
 
73384
74199
  // ../../packages/super-editor/src/document-api-adapters/plan-engine/lists-wrappers.ts
73385
74200
  function toListsFailure(code3, message, details) {
73386
74201
  return { success: false, failure: { code: code3, message, details } };
73387
74202
  }
74203
+ function dispatchEditorTransaction(editor, tr) {
74204
+ if (typeof editor.dispatch === "function") {
74205
+ editor.dispatch(tr);
74206
+ return;
74207
+ }
74208
+ if (typeof editor.view?.dispatch === "function") {
74209
+ editor.view.dispatch(tr);
74210
+ return;
74211
+ }
74212
+ throw new DocumentApiAdapterError("INTERNAL_ERROR", "Cannot apply list mutation because no transaction dispatcher is available.", { reason: "missing_dispatch" });
74213
+ }
73388
74214
  function resolveInsertedListItem(editor, sdBlockId) {
73389
74215
  const index2 = getBlockIndex(editor);
73390
74216
  const byNodeId = index2.candidates.find((candidate) => candidate.nodeType === "listItem" && candidate.nodeId === sdBlockId);
@@ -73401,54 +74227,71 @@ function resolveInsertedListItem(editor, sdBlockId) {
73401
74227
  }
73402
74228
  throw new DocumentApiAdapterError("TARGET_NOT_FOUND", `Inserted list item with sdBlockId "${sdBlockId}" could not be resolved after insertion.`);
73403
74229
  }
73404
- function selectionAnchorPos(item) {
73405
- return item.candidate.pos + 1;
73406
- }
73407
- function setSelectionToListItem(editor, item) {
73408
- const setTextSelection = requireEditorCommand(editor.commands?.setTextSelection, "lists (setTextSelection)");
73409
- const anchor = selectionAnchorPos(item);
73410
- return Boolean(setTextSelection({ from: anchor, to: anchor }));
74230
+ function withListTarget(editor, input) {
74231
+ return resolveListItem(editor, input.target);
73411
74232
  }
73412
- function isAtMaximumLevel(editor, item) {
73413
- if (item.numId == null || item.level == null)
73414
- return false;
73415
- return !ListHelpers.hasListDefinition(editor, item.numId, item.level + 1);
74233
+ function hasLevelOverride(editor, numId, level) {
74234
+ const converter = editor;
74235
+ const definition3 = converter.converter?.numbering?.definitions?.[numId];
74236
+ const ilvl = String(level);
74237
+ return definition3?.elements?.some((element) => element.name === "w:lvlOverride" && element.attributes?.["w:ilvl"] === ilvl) ?? false;
73416
74238
  }
73417
- function isRestartNoOp(editor, item) {
73418
- if (item.ordinal !== 1)
73419
- return false;
73420
- if (item.numId == null)
73421
- return false;
73422
- const index2 = getBlockIndex(editor);
73423
- const currentIndex = index2.candidates.findIndex((candidate) => candidate.nodeType === "listItem" && candidate.nodeId === item.address.nodeId);
73424
- if (currentIndex <= 0)
74239
+ function executeSetLevel(editor, target, newLevel, options) {
74240
+ if (target.numId == null) {
74241
+ return toListsFailure("INVALID_TARGET", "Target must have numbering metadata.", {
74242
+ target: target.address
74243
+ });
74244
+ }
74245
+ if (newLevel < 0 || newLevel > 8) {
74246
+ return toListsFailure("LEVEL_OUT_OF_RANGE", "Level must be between 0 and 8.", { level: newLevel });
74247
+ }
74248
+ if (target.level === newLevel) {
74249
+ return toListsFailure("NO_OP", "Item is already at the requested level.", {
74250
+ target: target.address,
74251
+ level: newLevel
74252
+ });
74253
+ }
74254
+ if (!ListHelpers.hasListDefinition(editor, target.numId, newLevel)) {
74255
+ return toListsFailure("LEVEL_OUT_OF_RANGE", "Target level is not defined in the active numbering definition.", {
74256
+ target: target.address,
74257
+ level: newLevel
74258
+ });
74259
+ }
74260
+ if (options?.dryRun) {
74261
+ return { success: true, item: target.address };
74262
+ }
74263
+ const receipt2 = executeDomainCommand(editor, () => {
74264
+ const { tr } = editor.state;
74265
+ updateNumberingProperties({ numId: target.numId, ilvl: newLevel }, target.candidate.node, target.candidate.pos, editor, tr);
74266
+ dispatchEditorTransaction(editor, tr);
74267
+ clearIndexCache(editor);
73425
74268
  return true;
73426
- for (let cursor = currentIndex - 1;cursor >= 0; cursor -= 1) {
73427
- const previous3 = index2.candidates[cursor];
73428
- if (previous3.node.type.name !== "paragraph") {
73429
- return true;
73430
- }
73431
- if (previous3.nodeType !== "listItem") {
73432
- return true;
73433
- }
73434
- const previousProjection = resolveListItem(editor, {
73435
- kind: "block",
73436
- nodeType: "listItem",
73437
- nodeId: previous3.nodeId
74269
+ }, { expectedRevision: options?.expectedRevision });
74270
+ if (receipt2.steps[0]?.effect !== "changed") {
74271
+ return toListsFailure("INVALID_TARGET", "Level change could not be applied.", {
74272
+ target: target.address,
74273
+ level: newLevel
73438
74274
  });
73439
- return previousProjection.numId !== item.numId || previousProjection.level !== item.level;
73440
74275
  }
73441
- return true;
74276
+ return { success: true, item: target.address };
73442
74277
  }
73443
- function withListTarget(editor, input) {
73444
- return resolveListItem(editor, input.target);
74278
+ function isBlockRange(target) {
74279
+ return typeof target === "object" && target !== null && "from" in target;
73445
74280
  }
73446
74281
  function listsListWrapper(editor, query2) {
73447
74282
  return listListItems(editor, query2);
73448
74283
  }
73449
74284
  function listsGetWrapper(editor, input) {
73450
74285
  const item = resolveListItem(editor, input.address);
73451
- return listItemProjectionToInfo(item);
74286
+ return listItemProjectionToInfo(item, computeSequenceId(editor, item));
74287
+ }
74288
+ function listsCanJoinWrapper(editor, input) {
74289
+ const target = resolveListItem(editor, input.target);
74290
+ return evaluateCanJoin(editor, target, input.direction);
74291
+ }
74292
+ function listsCanContinuePreviousWrapper(editor, input) {
74293
+ const target = resolveListItem(editor, input.target);
74294
+ return evaluateCanContinuePrevious(editor, target);
73452
74295
  }
73453
74296
  function listsInsertWrapper(editor, input, options) {
73454
74297
  const target = withListTarget(editor, input);
@@ -73492,7 +74335,8 @@ function listsInsertWrapper(editor, input, options) {
73492
74335
  position: input.position
73493
74336
  });
73494
74337
  }
73495
- if (!created) {
74338
+ const resolved = created;
74339
+ if (!resolved) {
73496
74340
  return {
73497
74341
  success: true,
73498
74342
  item: { kind: "block", nodeType: "listItem", nodeId: createdId },
@@ -73505,143 +74349,416 @@ function listsInsertWrapper(editor, input, options) {
73505
74349
  }
73506
74350
  return {
73507
74351
  success: true,
73508
- item: created.address,
74352
+ item: resolved.address,
73509
74353
  insertionPoint: {
73510
74354
  kind: "text",
73511
- blockId: created.address.nodeId,
74355
+ blockId: resolved.address.nodeId,
73512
74356
  range: { start: 0, end: 0 }
73513
74357
  },
73514
- trackedChangeRefs: mode === "tracked" ? collectTrackInsertRefsInRange(editor, created.candidate.pos, created.candidate.end) : undefined
74358
+ trackedChangeRefs: mode === "tracked" ? collectTrackInsertRefsInRange(editor, resolved.candidate.pos, resolved.candidate.end) : undefined
73515
74359
  };
73516
74360
  }
73517
- function listsSetTypeWrapper(editor, input, options) {
73518
- rejectTrackedMode("lists.setType", options);
74361
+ function listsIndentWrapper(editor, input, options) {
74362
+ rejectTrackedMode("lists.indent", options);
73519
74363
  const target = withListTarget(editor, input);
73520
- if (target.kind === input.kind) {
73521
- return toListsFailure("NO_OP", "List item already has the requested list kind.", {
74364
+ const currentLevel = target.level ?? 0;
74365
+ return executeSetLevel(editor, target, currentLevel + 1, options);
74366
+ }
74367
+ function listsOutdentWrapper(editor, input, options) {
74368
+ rejectTrackedMode("lists.outdent", options);
74369
+ const target = withListTarget(editor, input);
74370
+ const currentLevel = target.level ?? 0;
74371
+ if (currentLevel <= 0) {
74372
+ return toListsFailure("NO_OP", "List item is already at level 0.", { target: input.target });
74373
+ }
74374
+ return executeSetLevel(editor, target, currentLevel - 1, options);
74375
+ }
74376
+ function listsCreateWrapper(editor, input, options) {
74377
+ rejectTrackedMode("lists.create", options);
74378
+ const raw = input;
74379
+ if (input.mode === "empty" && raw.at == null) {
74380
+ return toListsFailure("INVALID_TARGET", 'Mode "empty" requires an "at" field.', { mode: "empty" });
74381
+ }
74382
+ if (input.mode === "fromParagraphs" && raw.target == null) {
74383
+ return toListsFailure("INVALID_TARGET", 'Mode "fromParagraphs" requires a "target" field.', {
74384
+ mode: "fromParagraphs"
74385
+ });
74386
+ }
74387
+ const level = input.level ?? 0;
74388
+ if (level < 0 || level > 8) {
74389
+ return toListsFailure("LEVEL_OUT_OF_RANGE", "Level must be between 0 and 8.", { level });
74390
+ }
74391
+ const listType = input.kind === "ordered" ? "orderedList" : "bulletList";
74392
+ if (input.mode === "empty") {
74393
+ const block = resolveBlock(editor, input.at.nodeId);
74394
+ if (block.nodeType === "listItem") {
74395
+ return toListsFailure("INVALID_TARGET", "Target paragraph is already a list item.", { target: input.at });
74396
+ }
74397
+ if (options?.dryRun) {
74398
+ return { success: true, listId: "(dry-run)", item: { kind: "block", nodeType: "listItem", nodeId: "(dry-run)" } };
74399
+ }
74400
+ let numId2;
74401
+ const receipt3 = executeDomainCommand(editor, () => {
74402
+ numId2 = ListHelpers.getNewListId(editor);
74403
+ ListHelpers.generateNewListDefinition({ numId: numId2, listType, editor });
74404
+ const { tr } = editor.state;
74405
+ updateNumberingProperties({ numId: numId2, ilvl: level }, block.node, block.pos, editor, tr);
74406
+ dispatchEditorTransaction(editor, tr);
74407
+ clearIndexCache(editor);
74408
+ return true;
74409
+ }, { expectedRevision: options?.expectedRevision });
74410
+ if (receipt3.steps[0]?.effect !== "changed") {
74411
+ return toListsFailure("INVALID_TARGET", "List creation could not be applied.", { mode: input.mode });
74412
+ }
74413
+ return {
74414
+ success: true,
74415
+ listId: `${numId2}:${block.nodeId}`,
74416
+ item: { kind: "block", nodeType: "listItem", nodeId: block.nodeId }
74417
+ };
74418
+ }
74419
+ const targets = isBlockRange(input.target) ? resolveBlocksInRange(editor, input.target.from.nodeId, input.target.to.nodeId) : [resolveBlock(editor, input.target.nodeId)];
74420
+ if (targets.length === 0) {
74421
+ return toListsFailure("INVALID_TARGET", "No paragraphs found in the specified range.", { target: input.target });
74422
+ }
74423
+ const alreadyListItem = targets.find((t) => t.nodeType === "listItem");
74424
+ if (alreadyListItem) {
74425
+ return toListsFailure("INVALID_TARGET", "One or more target paragraphs are already list items.", {
74426
+ nodeId: alreadyListItem.nodeId
74427
+ });
74428
+ }
74429
+ if (options?.dryRun) {
74430
+ return {
74431
+ success: true,
74432
+ listId: "(dry-run)",
74433
+ item: { kind: "block", nodeType: "listItem", nodeId: targets[0].nodeId }
74434
+ };
74435
+ }
74436
+ let numId;
74437
+ const receipt2 = executeDomainCommand(editor, () => {
74438
+ numId = ListHelpers.getNewListId(editor);
74439
+ ListHelpers.generateNewListDefinition({ numId, listType, editor });
74440
+ const { tr } = editor.state;
74441
+ for (const block of targets) {
74442
+ updateNumberingProperties({ numId, ilvl: level }, block.node, block.pos, editor, tr);
74443
+ }
74444
+ dispatchEditorTransaction(editor, tr);
74445
+ clearIndexCache(editor);
74446
+ return true;
74447
+ }, { expectedRevision: options?.expectedRevision });
74448
+ if (receipt2.steps[0]?.effect !== "changed") {
74449
+ return toListsFailure("INVALID_TARGET", "List creation could not be applied.", { mode: input.mode });
74450
+ }
74451
+ return {
74452
+ success: true,
74453
+ listId: `${numId}:${targets[0].nodeId}`,
74454
+ item: { kind: "block", nodeType: "listItem", nodeId: targets[0].nodeId }
74455
+ };
74456
+ }
74457
+ function listsAttachWrapper(editor, input, options) {
74458
+ rejectTrackedMode("lists.attach", options);
74459
+ const attachTo = resolveListItem(editor, input.attachTo);
74460
+ if (attachTo.numId == null) {
74461
+ return toListsFailure("INVALID_TARGET", "attachTo target must be a list item with numbering metadata.", {
74462
+ attachTo: input.attachTo
74463
+ });
74464
+ }
74465
+ const numId = attachTo.numId;
74466
+ const level = input.level ?? attachTo.level ?? 0;
74467
+ const targets = isBlockRange(input.target) ? resolveBlocksInRange(editor, input.target.from.nodeId, input.target.to.nodeId) : [resolveBlock(editor, input.target.nodeId)];
74468
+ if (targets.length === 0) {
74469
+ return toListsFailure("INVALID_TARGET", "No paragraphs found in the specified target.", { target: input.target });
74470
+ }
74471
+ const alreadyListItem = targets.find((t) => t.nodeType === "listItem");
74472
+ if (alreadyListItem) {
74473
+ return toListsFailure("INVALID_TARGET", "Target paragraphs are already list items.", {
74474
+ nodeId: alreadyListItem.nodeId
74475
+ });
74476
+ }
74477
+ if (options?.dryRun) {
74478
+ return { success: true, item: { kind: "block", nodeType: "listItem", nodeId: targets[0].nodeId } };
74479
+ }
74480
+ const receipt2 = executeDomainCommand(editor, () => {
74481
+ const { tr } = editor.state;
74482
+ for (const block of targets) {
74483
+ updateNumberingProperties({ numId, ilvl: level }, block.node, block.pos, editor, tr);
74484
+ }
74485
+ dispatchEditorTransaction(editor, tr);
74486
+ clearIndexCache(editor);
74487
+ return true;
74488
+ }, { expectedRevision: options?.expectedRevision });
74489
+ if (receipt2.steps[0]?.effect !== "changed") {
74490
+ return toListsFailure("INVALID_TARGET", "List attachment could not be applied.", { target: input.target });
74491
+ }
74492
+ return { success: true, item: { kind: "block", nodeType: "listItem", nodeId: targets[0].nodeId } };
74493
+ }
74494
+ function listsDetachWrapper(editor, input, options) {
74495
+ rejectTrackedMode("lists.detach", options);
74496
+ const target = resolveListItem(editor, input.target);
74497
+ if (options?.dryRun) {
74498
+ return { success: true, paragraph: { kind: "block", nodeType: "paragraph", nodeId: target.address.nodeId } };
74499
+ }
74500
+ const receipt2 = executeDomainCommand(editor, () => {
74501
+ const { tr } = editor.state;
74502
+ updateNumberingProperties(null, target.candidate.node, target.candidate.pos, editor, tr);
74503
+ dispatchEditorTransaction(editor, tr);
74504
+ clearIndexCache(editor);
74505
+ return true;
74506
+ }, { expectedRevision: options?.expectedRevision });
74507
+ if (receipt2.steps[0]?.effect !== "changed") {
74508
+ return toListsFailure("INVALID_TARGET", "List detach could not be applied.", { target: input.target });
74509
+ }
74510
+ return { success: true, paragraph: { kind: "block", nodeType: "paragraph", nodeId: target.address.nodeId } };
74511
+ }
74512
+ function listsJoinWrapper(editor, input, options) {
74513
+ rejectTrackedMode("lists.join", options);
74514
+ const target = resolveListItem(editor, input.target);
74515
+ if (target.numId == null) {
74516
+ return toListsFailure("INVALID_TARGET", "Target must have numbering metadata.", { target: input.target });
74517
+ }
74518
+ const canJoinResult = evaluateCanJoin(editor, target, input.direction);
74519
+ if (!canJoinResult.canJoin) {
74520
+ return toListsFailure(canJoinResult.reason, `Cannot join: ${canJoinResult.reason}`, {
73522
74521
  target: input.target,
73523
- kind: input.kind
74522
+ direction: input.direction
73524
74523
  });
73525
74524
  }
73526
- const setListTypeAt = requireEditorCommand(editor.commands?.setListTypeAt, "lists.setType (setListTypeAt)");
74525
+ const adjacent = findAdjacentSequence(editor, target, input.direction);
74526
+ let absorbingNumId;
74527
+ let absorbedItems;
74528
+ let anchorNodeId;
74529
+ if (input.direction === "withPrevious") {
74530
+ absorbingNumId = adjacent.numId;
74531
+ absorbedItems = getContiguousSequence(editor, target);
74532
+ anchorNodeId = adjacent.sequence[0]?.address.nodeId ?? target.address.nodeId;
74533
+ } else {
74534
+ absorbingNumId = target.numId;
74535
+ absorbedItems = adjacent.sequence;
74536
+ const targetSequence = getContiguousSequence(editor, target);
74537
+ anchorNodeId = targetSequence[0]?.address.nodeId ?? target.address.nodeId;
74538
+ }
74539
+ const mergedListId = `${absorbingNumId}:${anchorNodeId}`;
73527
74540
  if (options?.dryRun) {
73528
- return { success: true, item: target.address };
74541
+ return { success: true, listId: mergedListId };
73529
74542
  }
73530
- const receipt2 = executeDomainCommand(editor, () => setListTypeAt({ pos: target.candidate.pos, kind: input.kind }), {
73531
- expectedRevision: options?.expectedRevision
73532
- });
74543
+ const receipt2 = executeDomainCommand(editor, () => {
74544
+ const { tr } = editor.state;
74545
+ for (const item of absorbedItems) {
74546
+ const currentLevel = item.level ?? 0;
74547
+ updateNumberingProperties({ numId: absorbingNumId, ilvl: currentLevel }, item.candidate.node, item.candidate.pos, editor, tr);
74548
+ }
74549
+ dispatchEditorTransaction(editor, tr);
74550
+ clearIndexCache(editor);
74551
+ return true;
74552
+ }, { expectedRevision: options?.expectedRevision });
73533
74553
  if (receipt2.steps[0]?.effect !== "changed") {
73534
- return toListsFailure("INVALID_TARGET", "List type conversion could not be applied.", {
74554
+ return toListsFailure("INVALID_TARGET", "List join could not be applied.", {
73535
74555
  target: input.target,
73536
- kind: input.kind
74556
+ direction: input.direction
73537
74557
  });
73538
74558
  }
73539
- return { success: true, item: target.address };
74559
+ return { success: true, listId: mergedListId };
73540
74560
  }
73541
- function listsIndentWrapper(editor, input, options) {
73542
- rejectTrackedMode("lists.indent", options);
73543
- const target = withListTarget(editor, input);
73544
- if (isAtMaximumLevel(editor, target)) {
73545
- return toListsFailure("NO_OP", "List item is already at the maximum supported level.", { target: input.target });
74561
+ function listsSeparateWrapper(editor, input, options) {
74562
+ rejectTrackedMode("lists.separate", options);
74563
+ const target = resolveListItem(editor, input.target);
74564
+ if (target.numId == null) {
74565
+ return toListsFailure("INVALID_TARGET", "Target must have numbering metadata.", { target: input.target });
73546
74566
  }
73547
- const increaseListIndent = requireEditorCommand(editor.commands?.increaseListIndent, "lists.indent (increaseListIndent)");
73548
- if (options?.dryRun) {
73549
- return { success: true, item: target.address };
74567
+ if (isFirstInSequence(editor, target)) {
74568
+ return toListsFailure("NO_OP", "Target is already the first item in its sequence.", { target: input.target });
73550
74569
  }
73551
- if (!setSelectionToListItem(editor, target)) {
73552
- return toListsFailure("INVALID_TARGET", "List item target could not be selected for indentation.", {
74570
+ const copyOverrides = input.copyOverrides !== false;
74571
+ const abstractNumId = getAbstractNumId(editor, target.numId);
74572
+ if (abstractNumId == null) {
74573
+ return toListsFailure("INVALID_TARGET", "Could not resolve abstract definition for target.", {
73553
74574
  target: input.target
73554
74575
  });
73555
74576
  }
73556
- const receipt2 = executeDomainCommand(editor, () => increaseListIndent(), {
73557
- expectedRevision: options?.expectedRevision
73558
- });
74577
+ const itemsToReassign = getSequenceFromTarget(editor, target);
74578
+ if (options?.dryRun) {
74579
+ return { success: true, listId: "(dry-run)", numId: 0 };
74580
+ }
74581
+ let newNumId;
74582
+ const receipt2 = executeDomainCommand(editor, () => {
74583
+ const result = ListHelpers.createNumDefinition(editor, abstractNumId, {
74584
+ copyOverridesFrom: copyOverrides ? target.numId : undefined
74585
+ });
74586
+ newNumId = result.numId;
74587
+ const { tr } = editor.state;
74588
+ for (const item of itemsToReassign) {
74589
+ const currentLevel = item.level ?? 0;
74590
+ updateNumberingProperties({ numId: newNumId, ilvl: currentLevel }, item.candidate.node, item.candidate.pos, editor, tr);
74591
+ }
74592
+ dispatchEditorTransaction(editor, tr);
74593
+ clearIndexCache(editor);
74594
+ return true;
74595
+ }, { expectedRevision: options?.expectedRevision });
73559
74596
  if (receipt2.steps[0]?.effect !== "changed") {
73560
- return toListsFailure("INVALID_TARGET", "List indentation could not be applied.", { target: input.target });
74597
+ return toListsFailure("INVALID_TARGET", "List separation could not be applied.", { target: input.target });
73561
74598
  }
73562
- return { success: true, item: target.address };
74599
+ return { success: true, listId: `${newNumId}:${target.address.nodeId}`, numId: newNumId };
73563
74600
  }
73564
- function listsOutdentWrapper(editor, input, options) {
73565
- rejectTrackedMode("lists.outdent", options);
73566
- const target = withListTarget(editor, input);
73567
- if ((target.level ?? 0) <= 0) {
73568
- return toListsFailure("NO_OP", "List item is already at level 0.", { target: input.target });
74601
+ function listsSetLevelWrapper(editor, input, options) {
74602
+ rejectTrackedMode("lists.setLevel", options);
74603
+ const target = resolveListItem(editor, input.target);
74604
+ return executeSetLevel(editor, target, input.level, options);
74605
+ }
74606
+ function listsSetValueWrapper(editor, input, options) {
74607
+ rejectTrackedMode("lists.setValue", options);
74608
+ const target = resolveListItem(editor, input.target);
74609
+ if (target.numId == null) {
74610
+ return toListsFailure("INVALID_TARGET", "Target must have numbering metadata.", { target: input.target });
73569
74611
  }
73570
- const decreaseListIndent = requireEditorCommand(editor.commands?.decreaseListIndent, "lists.outdent (decreaseListIndent)");
74612
+ const level = target.level ?? 0;
73571
74613
  if (options?.dryRun) {
73572
74614
  return { success: true, item: target.address };
73573
74615
  }
73574
- if (!setSelectionToListItem(editor, target)) {
73575
- return toListsFailure("INVALID_TARGET", "List item target could not be selected for outdent.", {
74616
+ if (input.value === null) {
74617
+ if (!hasLevelOverride(editor, target.numId, level)) {
74618
+ return toListsFailure("NO_OP", "No startOverride to remove.", { target: input.target });
74619
+ }
74620
+ const receipt3 = executeDomainCommand(editor, () => {
74621
+ ListHelpers.removeLvlOverride(editor, target.numId, level);
74622
+ dispatchEditorTransaction(editor, editor.state.tr);
74623
+ return true;
74624
+ }, { expectedRevision: options?.expectedRevision });
74625
+ if (receipt3.steps[0]?.effect !== "changed") {
74626
+ return toListsFailure("NO_OP", "No startOverride to remove.", { target: input.target });
74627
+ }
74628
+ return { success: true, item: target.address };
74629
+ }
74630
+ const isFirst = isFirstInSequence(editor, target);
74631
+ if (isFirst) {
74632
+ const receipt3 = executeDomainCommand(editor, () => {
74633
+ ListHelpers.setLvlOverride(editor, target.numId, level, { startOverride: input.value });
74634
+ dispatchEditorTransaction(editor, editor.state.tr);
74635
+ return true;
74636
+ }, { expectedRevision: options?.expectedRevision });
74637
+ if (receipt3.steps[0]?.effect !== "changed") {
74638
+ return toListsFailure("INVALID_TARGET", "setValue could not be applied.", { target: input.target });
74639
+ }
74640
+ return { success: true, item: target.address };
74641
+ }
74642
+ const abstractNumId = getAbstractNumId(editor, target.numId);
74643
+ if (abstractNumId == null) {
74644
+ return toListsFailure("INVALID_TARGET", "Could not resolve abstract definition for target.", {
73576
74645
  target: input.target
73577
74646
  });
73578
74647
  }
73579
- const receipt2 = executeDomainCommand(editor, () => decreaseListIndent(), {
73580
- expectedRevision: options?.expectedRevision
73581
- });
74648
+ const itemsToReassign = getSequenceFromTarget(editor, target);
74649
+ const receipt2 = executeDomainCommand(editor, () => {
74650
+ const { numId: newNumId } = ListHelpers.createNumDefinition(editor, abstractNumId, {
74651
+ copyOverridesFrom: target.numId
74652
+ });
74653
+ ListHelpers.setLvlOverride(editor, newNumId, level, { startOverride: input.value });
74654
+ const { tr } = editor.state;
74655
+ for (const item of itemsToReassign) {
74656
+ const currentLevel = item.level ?? 0;
74657
+ updateNumberingProperties({ numId: newNumId, ilvl: currentLevel }, item.candidate.node, item.candidate.pos, editor, tr);
74658
+ }
74659
+ dispatchEditorTransaction(editor, tr);
74660
+ clearIndexCache(editor);
74661
+ return true;
74662
+ }, { expectedRevision: options?.expectedRevision });
73582
74663
  if (receipt2.steps[0]?.effect !== "changed") {
73583
- return toListsFailure("INVALID_TARGET", "List outdent could not be applied.", { target: input.target });
74664
+ return toListsFailure("INVALID_TARGET", "setValue could not be applied.", { target: input.target });
73584
74665
  }
73585
74666
  return { success: true, item: target.address };
73586
74667
  }
73587
- function listsRestartWrapper(editor, input, options) {
73588
- rejectTrackedMode("lists.restart", options);
73589
- const target = withListTarget(editor, input);
74668
+ function listsContinuePreviousWrapper(editor, input, options) {
74669
+ rejectTrackedMode("lists.continuePrevious", options);
74670
+ const target = resolveListItem(editor, input.target);
73590
74671
  if (target.numId == null) {
73591
- return toListsFailure("INVALID_TARGET", "List restart requires numbering metadata on the target item.", {
73592
- target: input.target
73593
- });
73594
- }
73595
- if (isRestartNoOp(editor, target)) {
73596
- return toListsFailure("NO_OP", "List item is already the start of a sequence that effectively starts at 1.", {
74672
+ return toListsFailure("INVALID_TARGET", "Target must have numbering metadata.", { target: input.target });
74673
+ }
74674
+ const canContinue = evaluateCanContinuePrevious(editor, target);
74675
+ if (!canContinue.canContinue) {
74676
+ const reasonToFailureCode = {
74677
+ NO_PREVIOUS_LIST: "NO_COMPATIBLE_PREVIOUS",
74678
+ INCOMPATIBLE_DEFINITIONS: "NO_COMPATIBLE_PREVIOUS",
74679
+ ALREADY_CONTINUOUS: "ALREADY_CONTINUOUS"
74680
+ };
74681
+ const code3 = reasonToFailureCode[canContinue.reason] ?? "INVALID_TARGET";
74682
+ return toListsFailure(code3, `Cannot continue previous: ${canContinue.reason}`, {
73597
74683
  target: input.target
73598
74684
  });
73599
74685
  }
73600
- const restartNumbering = requireEditorCommand(editor.commands?.restartNumbering, "lists.restart (restartNumbering)");
74686
+ const previous3 = findPreviousCompatibleSequence(editor, target);
73601
74687
  if (options?.dryRun) {
73602
74688
  return { success: true, item: target.address };
73603
74689
  }
73604
- if (!setSelectionToListItem(editor, target)) {
73605
- return toListsFailure("INVALID_TARGET", "List item target could not be selected for restart.", {
73606
- target: input.target
73607
- });
73608
- }
73609
- const receipt2 = executeDomainCommand(editor, () => restartNumbering(), {
73610
- expectedRevision: options?.expectedRevision
73611
- });
74690
+ const sequence = getContiguousSequence(editor, target);
74691
+ const level = target.level ?? 0;
74692
+ const receipt2 = executeDomainCommand(editor, () => {
74693
+ ListHelpers.removeLvlOverride(editor, target.numId, level);
74694
+ const { tr } = editor.state;
74695
+ for (const item of sequence) {
74696
+ const currentLevel = item.level ?? 0;
74697
+ updateNumberingProperties({ numId: previous3.numId, ilvl: currentLevel }, item.candidate.node, item.candidate.pos, editor, tr);
74698
+ }
74699
+ dispatchEditorTransaction(editor, tr);
74700
+ clearIndexCache(editor);
74701
+ return true;
74702
+ }, { expectedRevision: options?.expectedRevision });
73612
74703
  if (receipt2.steps[0]?.effect !== "changed") {
73613
- return toListsFailure("INVALID_TARGET", "List restart could not be applied.", { target: input.target });
74704
+ return toListsFailure("INVALID_TARGET", "continuePrevious could not be applied.", { target: input.target });
73614
74705
  }
73615
74706
  return { success: true, item: target.address };
73616
74707
  }
73617
- function listsExitWrapper(editor, input, options) {
73618
- rejectTrackedMode("lists.exit", options);
73619
- const target = withListTarget(editor, input);
73620
- const exitListItemAt = requireEditorCommand(editor.commands?.exitListItemAt, "lists.exit (exitListItemAt)");
74708
+ function listsSetLevelRestartWrapper(editor, input, options) {
74709
+ rejectTrackedMode("lists.setLevelRestart", options);
74710
+ const target = resolveListItem(editor, input.target);
74711
+ if (target.numId == null) {
74712
+ return toListsFailure("INVALID_TARGET", "Target must have numbering metadata.", { target: input.target });
74713
+ }
74714
+ if (input.level < 0 || input.level > 8) {
74715
+ return toListsFailure("LEVEL_OUT_OF_RANGE", "Level must be between 0 and 8.", { level: input.level });
74716
+ }
73621
74717
  if (options?.dryRun) {
73622
- return {
73623
- success: true,
73624
- paragraph: {
73625
- kind: "block",
73626
- nodeType: "paragraph",
73627
- nodeId: "(dry-run)"
73628
- }
73629
- };
74718
+ return { success: true, item: target.address };
73630
74719
  }
73631
- const receipt2 = executeDomainCommand(editor, () => exitListItemAt({ pos: target.candidate.pos }), {
73632
- expectedRevision: options?.expectedRevision
73633
- });
74720
+ const scope = input.scope ?? "definition";
74721
+ const receipt2 = executeDomainCommand(editor, () => {
74722
+ if (scope === "instance") {
74723
+ ListHelpers.setLvlOverride(editor, target.numId, input.level, {
74724
+ lvlRestart: input.restartAfterLevel
74725
+ });
74726
+ } else {
74727
+ const abstractNumId = getAbstractNumId(editor, target.numId);
74728
+ if (abstractNumId == null)
74729
+ return false;
74730
+ ListHelpers.setLvlRestartOnAbstract(editor, abstractNumId, input.level, input.restartAfterLevel);
74731
+ }
74732
+ dispatchEditorTransaction(editor, editor.state.tr);
74733
+ return true;
74734
+ }, { expectedRevision: options?.expectedRevision });
73634
74735
  if (receipt2.steps[0]?.effect !== "changed") {
73635
- return toListsFailure("INVALID_TARGET", "List exit could not be applied.", { target: input.target });
74736
+ return toListsFailure("INVALID_TARGET", "setLevelRestart could not be applied.", { target: input.target });
73636
74737
  }
73637
- return {
73638
- success: true,
73639
- paragraph: {
73640
- kind: "block",
73641
- nodeType: "paragraph",
73642
- nodeId: target.address.nodeId
74738
+ return { success: true, item: target.address };
74739
+ }
74740
+ function listsConvertToTextWrapper(editor, input, options) {
74741
+ rejectTrackedMode("lists.convertToText", options);
74742
+ const target = resolveListItem(editor, input.target);
74743
+ const includeMarker = input.includeMarker ?? false;
74744
+ if (options?.dryRun) {
74745
+ return { success: true, paragraph: { kind: "block", nodeType: "paragraph", nodeId: target.address.nodeId } };
74746
+ }
74747
+ const receipt2 = executeDomainCommand(editor, () => {
74748
+ const { tr } = editor.state;
74749
+ if (includeMarker && target.marker) {
74750
+ const startPos = target.candidate.pos + 1;
74751
+ tr.insertText(target.marker, startPos);
73643
74752
  }
73644
- };
74753
+ updateNumberingProperties(null, target.candidate.node, target.candidate.pos, editor, tr);
74754
+ dispatchEditorTransaction(editor, tr);
74755
+ clearIndexCache(editor);
74756
+ return true;
74757
+ }, { expectedRevision: options?.expectedRevision });
74758
+ if (receipt2.steps[0]?.effect !== "changed") {
74759
+ return toListsFailure("INVALID_TARGET", "convertToText could not be applied.", { target: input.target });
74760
+ }
74761
+ return { success: true, paragraph: { kind: "block", nodeType: "paragraph", nodeId: target.address.nodeId } };
73645
74762
  }
73646
74763
  var init_lists_wrappers = __esm(() => {
73647
74764
  init_wrapper();
@@ -73651,7 +74768,9 @@ var init_lists_wrappers = __esm(() => {
73651
74768
  init_index_cache();
73652
74769
  init_tracked_change_refs();
73653
74770
  init_list_item_resolver();
74771
+ init_list_sequence_helpers();
73654
74772
  init_list_numbering_helpers();
74773
+ init_changeListLevel();
73655
74774
  });
73656
74775
 
73657
74776
  // ../../packages/super-editor/src/document-api-adapters/plan-engine/preview.ts
@@ -80698,6 +81817,22 @@ function runTocCommand(editor, command, args2, expectedRevision) {
80698
81817
  const executeCommand = toTocEditorCommand(command);
80699
81818
  return runTocAction(editor, () => executeCommand(args2), expectedRevision);
80700
81819
  }
81820
+ function normalizeTocContent(content3, editor) {
81821
+ if (!Array.isArray(content3))
81822
+ return null;
81823
+ return content3.map((entry) => entry && typeof entry === "object" && typeof entry.type === "string" ? editor.state.schema.nodeFromJSON(entry) : entry);
81824
+ }
81825
+ function dispatchEditorTransaction2(editor, tr) {
81826
+ if (typeof editor.dispatch === "function") {
81827
+ editor.dispatch(tr);
81828
+ return;
81829
+ }
81830
+ if (typeof editor.view?.dispatch === "function") {
81831
+ editor.view.dispatch(tr);
81832
+ return;
81833
+ }
81834
+ throw new Error("No transaction dispatcher available.");
81835
+ }
80701
81836
  function receiptApplied(receipt2) {
80702
81837
  return receipt2.steps[0]?.effect === "changed";
80703
81838
  }
@@ -80733,20 +81868,49 @@ function withRightAlign(config33, rightAlignPageNumbers) {
80733
81868
  return config33;
80734
81869
  return { ...config33, display: { ...config33.display, rightAlignPageNumbers } };
80735
81870
  }
80736
- function materializeTocContent(doc, config33) {
81871
+ function sanitizeTocContentForSchema(content3, editor) {
81872
+ if (editor.state.schema?.marks?.tocPageNumber)
81873
+ return content3;
81874
+ return content3.map((paragraph2) => {
81875
+ const paragraphContent = paragraph2.content;
81876
+ if (!Array.isArray(paragraphContent))
81877
+ return paragraph2;
81878
+ let changed = false;
81879
+ const sanitizedContent = paragraphContent.map((node3) => {
81880
+ if (!node3 || typeof node3 !== "object")
81881
+ return node3;
81882
+ const typedNode = node3;
81883
+ const marks = typedNode.marks;
81884
+ if (!Array.isArray(marks))
81885
+ return node3;
81886
+ const filteredMarks = marks.filter((mark) => mark?.type !== "tocPageNumber");
81887
+ if (filteredMarks.length === marks.length)
81888
+ return node3;
81889
+ changed = true;
81890
+ if (filteredMarks.length === 0) {
81891
+ const { marks: _removed, ...rest } = typedNode;
81892
+ return rest;
81893
+ }
81894
+ return { ...typedNode, marks: filteredMarks };
81895
+ });
81896
+ return changed ? { ...paragraph2, content: sanitizedContent } : paragraph2;
81897
+ });
81898
+ }
81899
+ function materializeTocContent(doc, config33, editor) {
80737
81900
  const sources = collectTocSources(doc, config33);
80738
81901
  const entryParagraphs = buildTocEntryParagraphs(sources, config33);
80739
- return entryParagraphs.length > 0 ? entryParagraphs : NO_ENTRIES_PLACEHOLDER;
81902
+ const content3 = entryParagraphs.length > 0 ? entryParagraphs : NO_ENTRIES_PLACEHOLDER;
81903
+ return sanitizeTocContentForSchema(content3, editor);
80740
81904
  }
80741
81905
  function tocConfigureWrapper(editor, input, options) {
80742
81906
  rejectTrackedMode("toc.configure", options);
80743
- const command = requireEditorCommand(editor.commands?.setTableOfContentsInstructionById, "toc.configure");
80744
81907
  const resolved = resolveTocTarget(editor.state.doc, input.target);
80745
81908
  const currentConfig = parseTocInstruction(resolved.node.attrs?.instruction ?? "");
80746
81909
  const patched = applyTocPatchTyped(currentConfig, input.patch);
81910
+ const instruction = serializeTocInstruction(patched);
80747
81911
  const rightAlignChanged = input.patch.rightAlignPageNumbers !== undefined && input.patch.rightAlignPageNumbers !== resolved.node.attrs?.rightAlignPageNumbers;
80748
81912
  const effectiveRightAlign = input.patch.rightAlignPageNumbers ?? resolved.node.attrs?.rightAlignPageNumbers;
80749
- const nextContent = materializeTocContent(editor.state.doc, withRightAlign(patched, effectiveRightAlign));
81913
+ const nextContent = materializeTocContent(editor.state.doc, withRightAlign(patched, effectiveRightAlign), editor);
80750
81914
  if (areTocConfigsEqual(currentConfig, patched) && !rightAlignChanged) {
80751
81915
  return tocFailure("NO_OP", "Configuration patch produced no change.");
80752
81916
  }
@@ -80754,12 +81918,31 @@ function tocConfigureWrapper(editor, input, options) {
80754
81918
  return tocSuccess(resolved.nodeId);
80755
81919
  }
80756
81920
  const shouldRefreshContent = !isTocContentUnchanged(resolved.node, nextContent);
81921
+ const command = editor.commands?.setTableOfContentsInstructionById;
80757
81922
  const commandNodeId = resolved.commandNodeId ?? resolved.nodeId;
80758
- const receipt2 = runTocCommand(editor, command, {
81923
+ const receipt2 = typeof command === "function" ? runTocCommand(editor, command, {
80759
81924
  sdBlockId: commandNodeId,
80760
- instruction: serializeTocInstruction(patched),
81925
+ instruction,
80761
81926
  ...shouldRefreshContent ? { content: nextContent } : {},
80762
81927
  ...rightAlignChanged ? { rightAlignPageNumbers: input.patch.rightAlignPageNumbers } : {}
81928
+ }, options?.expectedRevision) : runTocAction(editor, () => {
81929
+ try {
81930
+ const { tr } = editor.state;
81931
+ tr.setNodeMarkup(resolved.pos, undefined, {
81932
+ ...resolved.node.attrs,
81933
+ instruction,
81934
+ ...rightAlignChanged ? { rightAlignPageNumbers: input.patch.rightAlignPageNumbers } : {}
81935
+ });
81936
+ if (shouldRefreshContent) {
81937
+ const from3 = resolved.pos + 1;
81938
+ const to = resolved.pos + resolved.node.nodeSize - 1;
81939
+ tr.replaceWith(from3, to, normalizeTocContent(nextContent, editor) ?? []);
81940
+ }
81941
+ dispatchEditorTransaction2(editor, tr);
81942
+ return true;
81943
+ } catch {
81944
+ return false;
81945
+ }
80763
81946
  }, options?.expectedRevision);
80764
81947
  if (!receiptApplied(receipt2)) {
80765
81948
  return tocFailure("NO_OP", "Configuration change could not be applied.");
@@ -80776,20 +81959,31 @@ function tocUpdateWrapper(editor, input, options) {
80776
81959
  return tocUpdateAll(editor, input, options);
80777
81960
  }
80778
81961
  function tocUpdateAll(editor, input, options) {
80779
- const command = requireEditorCommand(editor.commands?.replaceTableOfContentsContentById, "toc.update");
80780
81962
  const resolved = resolveTocTarget(editor.state.doc, input.target);
80781
81963
  const config33 = parseTocInstruction(resolved.node.attrs?.instruction ?? "");
80782
81964
  const rightAlign = resolved.node.attrs?.rightAlignPageNumbers;
80783
- const content3 = materializeTocContent(editor.state.doc, withRightAlign(config33, rightAlign));
81965
+ const content3 = materializeTocContent(editor.state.doc, withRightAlign(config33, rightAlign), editor);
80784
81966
  if (isTocContentUnchanged(resolved.node, content3)) {
80785
81967
  return tocFailure("NO_OP", "TOC update produced no change.");
80786
81968
  }
80787
81969
  if (options?.dryRun) {
80788
81970
  return tocSuccess(resolved.nodeId);
80789
81971
  }
80790
- const receipt2 = runTocCommand(editor, command, {
81972
+ const command = editor.commands?.replaceTableOfContentsContentById;
81973
+ const receipt2 = typeof command === "function" ? runTocCommand(editor, command, {
80791
81974
  sdBlockId: resolved.commandNodeId ?? resolved.nodeId,
80792
81975
  content: content3
81976
+ }, options?.expectedRevision) : runTocAction(editor, () => {
81977
+ try {
81978
+ const { tr } = editor.state;
81979
+ const from3 = resolved.pos + 1;
81980
+ const to = resolved.pos + resolved.node.nodeSize - 1;
81981
+ tr.replaceWith(from3, to, normalizeTocContent(content3, editor) ?? []);
81982
+ dispatchEditorTransaction2(editor, tr);
81983
+ return true;
81984
+ } catch {
81985
+ return false;
81986
+ }
80793
81987
  }, options?.expectedRevision);
80794
81988
  return receiptApplied(receipt2) ? tocSuccess(resolved.nodeId) : tocFailure("NO_OP", "TOC update produced no change.");
80795
81989
  }
@@ -80806,7 +82000,6 @@ function getPageMap(editor) {
80806
82000
  return tocStorage.pageMap;
80807
82001
  }
80808
82002
  function tocUpdatePageNumbers(editor, input, options) {
80809
- const command = requireEditorCommand(editor.commands?.replaceTableOfContentsContentById, "toc.update");
80810
82003
  const resolved = resolveTocTarget(editor.state.doc, input.target);
80811
82004
  const config33 = parseTocInstruction(resolved.node.attrs?.instruction ?? "");
80812
82005
  if (deriveIncludePageNumbers(config33.display.omitPageNumberLevels, config33.source.outlineLevels) === false) {
@@ -80826,9 +82019,21 @@ function tocUpdatePageNumbers(editor, input, options) {
80826
82019
  if (options?.dryRun) {
80827
82020
  return tocSuccess(resolved.nodeId);
80828
82021
  }
80829
- const receipt2 = runTocCommand(editor, command, {
82022
+ const command = editor.commands?.replaceTableOfContentsContentById;
82023
+ const receipt2 = typeof command === "function" ? runTocCommand(editor, command, {
80830
82024
  sdBlockId: resolved.commandNodeId ?? resolved.nodeId,
80831
82025
  content: updatedContent
82026
+ }, options?.expectedRevision) : runTocAction(editor, () => {
82027
+ try {
82028
+ const { tr } = editor.state;
82029
+ const from3 = resolved.pos + 1;
82030
+ const to = resolved.pos + resolved.node.nodeSize - 1;
82031
+ tr.replaceWith(from3, to, normalizeTocContent(updatedContent, editor) ?? []);
82032
+ dispatchEditorTransaction2(editor, tr);
82033
+ return true;
82034
+ } catch {
82035
+ return false;
82036
+ }
80832
82037
  }, options?.expectedRevision);
80833
82038
  return receiptApplied(receipt2) ? tocSuccess(resolved.nodeId) : tocFailure("NO_OP", "Page number update produced no change.");
80834
82039
  }
@@ -80872,19 +82077,27 @@ function buildPageNumberUpdatedContent(tocNode, pageMap) {
80872
82077
  }
80873
82078
  function tocRemoveWrapper(editor, input, options) {
80874
82079
  rejectTrackedMode("toc.remove", options);
80875
- const command = requireEditorCommand(editor.commands?.deleteTableOfContentsById, "toc.remove");
80876
82080
  const resolved = resolveTocTarget(editor.state.doc, input.target);
80877
82081
  if (options?.dryRun) {
80878
82082
  return tocSuccess(resolved.nodeId);
80879
82083
  }
80880
- const receipt2 = runTocCommand(editor, command, {
82084
+ const command = editor.commands?.deleteTableOfContentsById;
82085
+ const receipt2 = typeof command === "function" ? runTocCommand(editor, command, {
80881
82086
  sdBlockId: resolved.commandNodeId ?? resolved.nodeId
82087
+ }, options?.expectedRevision) : runTocAction(editor, () => {
82088
+ try {
82089
+ const { tr } = editor.state;
82090
+ tr.delete(resolved.pos, resolved.pos + resolved.node.nodeSize);
82091
+ dispatchEditorTransaction2(editor, tr);
82092
+ return true;
82093
+ } catch {
82094
+ return false;
82095
+ }
80882
82096
  }, options?.expectedRevision);
80883
82097
  return receiptApplied(receipt2) ? tocSuccess(resolved.nodeId) : tocFailure("NO_OP", "TOC removal produced no change.");
80884
82098
  }
80885
82099
  function createTableOfContentsWrapper(editor, input, options) {
80886
82100
  rejectTrackedMode("create.tableOfContents", options);
80887
- const command = requireEditorCommand(editor.commands?.insertTableOfContentsAt, "create.tableOfContents");
80888
82101
  const at = input.at ?? { kind: "documentEnd" };
80889
82102
  let pos;
80890
82103
  if (at.kind === "documentStart") {
@@ -80896,17 +82109,42 @@ function createTableOfContentsWrapper(editor, input, options) {
80896
82109
  }
80897
82110
  const config33 = input.config ? applyTocPatchTyped(DEFAULT_TOC_CONFIG, input.config) : DEFAULT_TOC_CONFIG;
80898
82111
  const instruction = serializeTocInstruction(config33);
80899
- const content3 = materializeTocContent(editor.state.doc, withRightAlign(config33, input.config?.rightAlignPageNumbers));
82112
+ const content3 = materializeTocContent(editor.state.doc, withRightAlign(config33, input.config?.rightAlignPageNumbers), editor);
80900
82113
  const sdBlockId = v4();
80901
82114
  if (options?.dryRun) {
80902
82115
  return { success: true, toc: buildTocAddress("(dry-run)") };
80903
82116
  }
80904
- const receipt2 = runTocCommand(editor, command, {
82117
+ const command = editor.commands?.insertTableOfContentsAt;
82118
+ const receipt2 = typeof command === "function" ? runTocCommand(editor, command, {
80905
82119
  pos,
80906
82120
  instruction,
80907
82121
  sdBlockId,
80908
82122
  content: content3,
80909
82123
  ...input.config?.rightAlignPageNumbers !== undefined ? { rightAlignPageNumbers: input.config.rightAlignPageNumbers } : {}
82124
+ }, options?.expectedRevision) : runTocAction(editor, () => {
82125
+ const tocType = editor.state.schema.nodes.tableOfContents;
82126
+ const paragraphType = editor.state.schema.nodes.paragraph;
82127
+ if (!tocType || !paragraphType)
82128
+ return false;
82129
+ const defaultContent = [
82130
+ paragraphType.create({}, editor.state.schema.text("Update table of contents to populate entries."))
82131
+ ];
82132
+ const materializedContent = normalizeTocContent(content3, editor) ?? defaultContent;
82133
+ const tocNode = tocType.create({
82134
+ instruction,
82135
+ sdBlockId,
82136
+ ...input.config?.rightAlignPageNumbers !== undefined ? { rightAlignPageNumbers: input.config.rightAlignPageNumbers } : {}
82137
+ }, materializedContent);
82138
+ try {
82139
+ const { tr } = editor.state;
82140
+ tr.insert(pos, tocNode);
82141
+ dispatchEditorTransaction2(editor, tr);
82142
+ return true;
82143
+ } catch (error) {
82144
+ if (error instanceof RangeError)
82145
+ return false;
82146
+ throw error;
82147
+ }
80910
82148
  }, options?.expectedRevision);
80911
82149
  if (!receiptApplied(receipt2)) {
80912
82150
  return {
@@ -81282,11 +82520,20 @@ function assembleDocumentApiAdapters(editor) {
81282
82520
  list: (query2) => listsListWrapper(editor, query2),
81283
82521
  get: (input) => listsGetWrapper(editor, input),
81284
82522
  insert: (input, options) => listsInsertWrapper(editor, input, options),
81285
- setType: (input, options) => listsSetTypeWrapper(editor, input, options),
82523
+ create: (input, options) => listsCreateWrapper(editor, input, options),
82524
+ attach: (input, options) => listsAttachWrapper(editor, input, options),
82525
+ detach: (input, options) => listsDetachWrapper(editor, input, options),
81286
82526
  indent: (input, options) => listsIndentWrapper(editor, input, options),
81287
82527
  outdent: (input, options) => listsOutdentWrapper(editor, input, options),
81288
- restart: (input, options) => listsRestartWrapper(editor, input, options),
81289
- exit: (input, options) => listsExitWrapper(editor, input, options)
82528
+ join: (input, options) => listsJoinWrapper(editor, input, options),
82529
+ canJoin: (input) => listsCanJoinWrapper(editor, input),
82530
+ separate: (input, options) => listsSeparateWrapper(editor, input, options),
82531
+ setLevel: (input, options) => listsSetLevelWrapper(editor, input, options),
82532
+ setValue: (input, options) => listsSetValueWrapper(editor, input, options),
82533
+ continuePrevious: (input, options) => listsContinuePreviousWrapper(editor, input, options),
82534
+ canContinuePrevious: (input) => listsCanContinuePreviousWrapper(editor, input),
82535
+ setLevelRestart: (input, options) => listsSetLevelRestartWrapper(editor, input, options),
82536
+ convertToText: (input, options) => listsConvertToTextWrapper(editor, input, options)
81290
82537
  },
81291
82538
  sections: {
81292
82539
  list: (query2) => sectionsListAdapter2(editor, query2),
@@ -85606,11 +86853,20 @@ var init_invoke_input = __esm(() => {
85606
86853
  getNode: "address",
85607
86854
  "lists.list": "query",
85608
86855
  "lists.insert": "input",
85609
- "lists.setType": "input",
85610
86856
  "lists.indent": "input",
85611
86857
  "lists.outdent": "input",
85612
- "lists.restart": "input",
85613
- "lists.exit": "input",
86858
+ "lists.create": "input",
86859
+ "lists.attach": "input",
86860
+ "lists.detach": "input",
86861
+ "lists.join": "input",
86862
+ "lists.canJoin": "input",
86863
+ "lists.separate": "input",
86864
+ "lists.setLevel": "input",
86865
+ "lists.setValue": "input",
86866
+ "lists.continuePrevious": "input",
86867
+ "lists.canContinuePrevious": "input",
86868
+ "lists.setLevelRestart": "input",
86869
+ "lists.convertToText": "input",
85614
86870
  "create.paragraph": "input",
85615
86871
  "create.heading": "input"
85616
86872
  };
@@ -85633,11 +86889,15 @@ var init_invoke_input = __esm(() => {
85633
86889
  ]);
85634
86890
  LIST_TARGET_OPERATIONS = new Set([
85635
86891
  "lists.insert",
85636
- "lists.setType",
85637
86892
  "lists.indent",
85638
86893
  "lists.outdent",
85639
- "lists.restart",
85640
- "lists.exit"
86894
+ "lists.detach",
86895
+ "lists.separate",
86896
+ "lists.setLevel",
86897
+ "lists.setValue",
86898
+ "lists.continuePrevious",
86899
+ "lists.canContinuePrevious",
86900
+ "lists.convertToText"
85641
86901
  ]);
85642
86902
  });
85643
86903
 
@@ -86141,6 +87401,15 @@ function buildHelperSpecs() {
86141
87401
  var CLI_HELPER_COMMANDS;
86142
87402
  var init_helper_commands = __esm(() => {
86143
87403
  CLI_HELPER_COMMANDS = [
87404
+ {
87405
+ tokens: ["lists", "exit"],
87406
+ canonicalOperationId: "lists.detach",
87407
+ defaultInput: {},
87408
+ description: "Alias for lists detach.",
87409
+ category: "lists",
87410
+ mutates: true,
87411
+ examples: [`superdoc lists exit --target-json '{"kind":"block","nodeType":"listItem","nodeId":"p1"}'`]
87412
+ },
86144
87413
  {
86145
87414
  tokens: ["format", "strikethrough"],
86146
87415
  canonicalOperationId: "format.strike",
@@ -86761,23 +88030,47 @@ var init_operation_params = __esm(() => {
86761
88030
  { name: "input", kind: "jsonFlag", flag: "input-json", type: "json" },
86762
88031
  ...LIST_TARGET_FLAT_PARAMS
86763
88032
  ],
86764
- "doc.lists.setType": [
88033
+ "doc.lists.indent": [
86765
88034
  { name: "input", kind: "jsonFlag", flag: "input-json", type: "json" },
86766
88035
  ...LIST_TARGET_FLAT_PARAMS
86767
88036
  ],
86768
- "doc.lists.indent": [
88037
+ "doc.lists.outdent": [
86769
88038
  { name: "input", kind: "jsonFlag", flag: "input-json", type: "json" },
86770
88039
  ...LIST_TARGET_FLAT_PARAMS
86771
88040
  ],
86772
- "doc.lists.outdent": [
88041
+ "doc.lists.create": [{ name: "input", kind: "jsonFlag", flag: "input-json", type: "json" }],
88042
+ "doc.lists.attach": [{ name: "input", kind: "jsonFlag", flag: "input-json", type: "json" }],
88043
+ "doc.lists.detach": [
86773
88044
  { name: "input", kind: "jsonFlag", flag: "input-json", type: "json" },
86774
88045
  ...LIST_TARGET_FLAT_PARAMS
86775
88046
  ],
86776
- "doc.lists.restart": [
88047
+ "doc.lists.join": [{ name: "input", kind: "jsonFlag", flag: "input-json", type: "json" }],
88048
+ "doc.lists.canJoin": [{ name: "input", kind: "jsonFlag", flag: "input-json", type: "json" }],
88049
+ "doc.lists.separate": [
88050
+ { name: "input", kind: "jsonFlag", flag: "input-json", type: "json" },
88051
+ ...LIST_TARGET_FLAT_PARAMS
88052
+ ],
88053
+ "doc.lists.setLevel": [
88054
+ { name: "input", kind: "jsonFlag", flag: "input-json", type: "json" },
88055
+ ...LIST_TARGET_FLAT_PARAMS
88056
+ ],
88057
+ "doc.lists.setValue": [
88058
+ { name: "input", kind: "jsonFlag", flag: "input-json", type: "json" },
88059
+ ...LIST_TARGET_FLAT_PARAMS
88060
+ ],
88061
+ "doc.lists.continuePrevious": [
88062
+ { name: "input", kind: "jsonFlag", flag: "input-json", type: "json" },
88063
+ ...LIST_TARGET_FLAT_PARAMS
88064
+ ],
88065
+ "doc.lists.canContinuePrevious": [
88066
+ { name: "input", kind: "jsonFlag", flag: "input-json", type: "json" },
88067
+ ...LIST_TARGET_FLAT_PARAMS
88068
+ ],
88069
+ "doc.lists.setLevelRestart": [{ name: "input", kind: "jsonFlag", flag: "input-json", type: "json" }],
88070
+ "doc.lists.convertToText": [
86777
88071
  { name: "input", kind: "jsonFlag", flag: "input-json", type: "json" },
86778
88072
  ...LIST_TARGET_FLAT_PARAMS
86779
88073
  ],
86780
- "doc.lists.exit": [{ name: "input", kind: "jsonFlag", flag: "input-json", type: "json" }, ...LIST_TARGET_FLAT_PARAMS],
86781
88074
  "doc.blocks.delete": [
86782
88075
  { name: "nodeType", kind: "flag", flag: "node-type", type: "string" },
86783
88076
  { name: "nodeId", kind: "flag", flag: "node-id", type: "string" }
@@ -95286,8 +96579,11 @@ async function executeParsedInvocation(parsed, io, executionMode, collabSessionP
95286
96579
  async function invokeCommand(argv, options = {}) {
95287
96580
  const io = mergeIo(options.ioOverrides);
95288
96581
  const startedAt = io.now();
95289
- const parsed = parseInvocation(argv);
95290
- const output = await executeParsedInvocation(parsed, io, options.executionMode ?? "oneshot", options.collabSessionPool);
96582
+ const { parsed, output } = await withStateDirOverride(options.stateDir, async () => {
96583
+ const parsedInvocation = parseInvocation(argv);
96584
+ const commandOutput = await executeParsedInvocation(parsedInvocation, io, options.executionMode ?? "oneshot", options.collabSessionPool);
96585
+ return { parsed: parsedInvocation, output: commandOutput };
96586
+ });
95291
96587
  return {
95292
96588
  globals: parsed.globals,
95293
96589
  execution: output.execution,
@@ -95299,51 +96595,53 @@ async function runHostCommand(tokens, io) {
95299
96595
  const { runHostStdio: runHostStdio2 } = await init_server().then(() => exports_server);
95300
96596
  return runHostStdio2(tokens, io);
95301
96597
  }
95302
- async function run(argv, ioOverrides) {
96598
+ async function run(argv, ioOverrides, options = {}) {
95303
96599
  const io = mergeIo(ioOverrides);
95304
96600
  const startedAt = io.now();
95305
96601
  let outputMode = "json";
95306
- try {
95307
- const parsed = parseInvocation(argv);
95308
- outputMode = parsed.globals.output;
95309
- if (parsed.rest[0] === "host") {
95310
- const hostTokens = parsed.rest.slice(1);
95311
- if (parsed.globals.help)
95312
- hostTokens.push("--help");
95313
- return await runHostCommand(hostTokens, io);
95314
- }
95315
- if (parsed.rest[0] === "install" && !parsed.globals.help) {
95316
- return await runInstall(parsed.rest.slice(1), io);
95317
- }
95318
- if (parsed.rest[0] === "uninstall" && !parsed.globals.help) {
95319
- return await runUninstall(parsed.rest.slice(1), io);
95320
- }
95321
- if (parsed.rest[0] === "call" && outputMode !== "json") {
95322
- throw new CliError("INVALID_ARGUMENT", "call: only --output json is supported.");
95323
- }
95324
- if (!parsed.globals.help) {
95325
- const legacyCompat = await tryRunLegacyCompatCommand(argv, parsed.rest, io);
95326
- if (legacyCompat.handled) {
95327
- return legacyCompat.exitCode;
96602
+ return withStateDirOverride(options.stateDir, async () => {
96603
+ try {
96604
+ const parsed = parseInvocation(argv);
96605
+ outputMode = parsed.globals.output;
96606
+ if (parsed.rest[0] === "host") {
96607
+ const hostTokens = parsed.rest.slice(1);
96608
+ if (parsed.globals.help)
96609
+ hostTokens.push("--help");
96610
+ return await runHostCommand(hostTokens, io);
95328
96611
  }
95329
- }
95330
- const output = await executeParsedInvocation(parsed, io, "oneshot");
95331
- if (output.helpText) {
95332
- io.stdout(output.helpText);
96612
+ if (parsed.rest[0] === "install" && !parsed.globals.help) {
96613
+ return await runInstall(parsed.rest.slice(1), io);
96614
+ }
96615
+ if (parsed.rest[0] === "uninstall" && !parsed.globals.help) {
96616
+ return await runUninstall(parsed.rest.slice(1), io);
96617
+ }
96618
+ if (parsed.rest[0] === "call" && outputMode !== "json") {
96619
+ throw new CliError("INVALID_ARGUMENT", "call: only --output json is supported.");
96620
+ }
96621
+ if (!parsed.globals.help) {
96622
+ const legacyCompat = await tryRunLegacyCompatCommand(argv, parsed.rest, io);
96623
+ if (legacyCompat.handled) {
96624
+ return legacyCompat.exitCode;
96625
+ }
96626
+ }
96627
+ const output = await executeParsedInvocation(parsed, io, "oneshot");
96628
+ if (output.helpText) {
96629
+ io.stdout(output.helpText);
96630
+ return 0;
96631
+ }
96632
+ if (!output.execution) {
96633
+ throw new CliError("COMMAND_FAILED", "Command produced no execution result and no help text.");
96634
+ }
96635
+ const elapsedMs = io.now() - startedAt;
96636
+ writeSuccess(io, outputMode, output.execution, elapsedMs);
95333
96637
  return 0;
96638
+ } catch (error) {
96639
+ const cliError = toCliError(error);
96640
+ const elapsedMs = io.now() - startedAt;
96641
+ writeFailure(io, outputMode, cliError, elapsedMs);
96642
+ return cliError.exitCode;
95334
96643
  }
95335
- if (!output.execution) {
95336
- throw new CliError("COMMAND_FAILED", "Command produced no execution result and no help text.");
95337
- }
95338
- const elapsedMs = io.now() - startedAt;
95339
- writeSuccess(io, outputMode, output.execution, elapsedMs);
95340
- return 0;
95341
- } catch (error) {
95342
- const cliError = toCliError(error);
95343
- const elapsedMs = io.now() - startedAt;
95344
- writeFailure(io, outputMode, cliError, elapsedMs);
95345
- return cliError.exitCode;
95346
- }
96644
+ });
95347
96645
  }
95348
96646
  var HELP, MANUAL_COMMANDS, EXTRA_COMMAND_KEYS, COMMAND_KEY_SET, CLI_COMMAND_KEY_SET, MANUAL_COMMAND_KEY_SET, COMMAND_OPERATION_ID_BY_KEY;
95349
96647
  var init_src2 = __esm(async () => {
@@ -95365,6 +96663,7 @@ var init_src2 = __esm(async () => {
95365
96663
  init_operation_args();
95366
96664
  init_install();
95367
96665
  init_uninstall();
96666
+ init_context();
95368
96667
  init_cli();
95369
96668
  HELP = [
95370
96669
  CLI_HELP,