@uiw/react-md-editor 3.20.10 → 3.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/mdeditor.js CHANGED
@@ -17364,123 +17364,123 @@ __webpack_require__.r(__webpack_exports__);
17364
17364
 
17365
17365
  // EXPORTS
17366
17366
  __webpack_require__.d(__webpack_exports__, {
17367
- "EditorContext": () => (/* reexport */ EditorContext),
17368
- "MarkdownUtil": () => (/* reexport */ markdownUtils_namespaceObject),
17369
- "TextAreaCommandOrchestrator": () => (/* reexport */ TextAreaCommandOrchestrator),
17370
- "TextAreaTextApi": () => (/* reexport */ TextAreaTextApi),
17371
- "bold": () => (/* reexport */ bold),
17372
- "checkedListCommand": () => (/* reexport */ checkedListCommand),
17373
- "code": () => (/* reexport */ code_code),
17374
- "codeBlock": () => (/* reexport */ codeBlock),
17375
- "codeEdit": () => (/* reexport */ codeEdit),
17376
- "codeLive": () => (/* reexport */ codeLive),
17377
- "codePreview": () => (/* reexport */ codePreview),
17378
- "commands": () => (/* reexport */ commands_namespaceObject),
17379
- "comment": () => (/* reexport */ commands_comment_comment),
17367
+ EditorContext: () => (/* reexport */ EditorContext),
17368
+ MarkdownUtil: () => (/* reexport */ markdownUtils_namespaceObject),
17369
+ TextAreaCommandOrchestrator: () => (/* reexport */ TextAreaCommandOrchestrator),
17370
+ TextAreaTextApi: () => (/* reexport */ TextAreaTextApi),
17371
+ bold: () => (/* reexport */ bold),
17372
+ checkedListCommand: () => (/* reexport */ checkedListCommand),
17373
+ code: () => (/* reexport */ code_code),
17374
+ codeBlock: () => (/* reexport */ codeBlock),
17375
+ codeEdit: () => (/* reexport */ codeEdit),
17376
+ codeLive: () => (/* reexport */ codeLive),
17377
+ codePreview: () => (/* reexport */ codePreview),
17378
+ commands: () => (/* reexport */ commands_namespaceObject),
17379
+ comment: () => (/* reexport */ commands_comment_comment),
17380
17380
  "default": () => (/* binding */ src_0),
17381
- "divider": () => (/* reexport */ divider),
17382
- "fullscreen": () => (/* reexport */ fullscreen),
17383
- "getBreaksNeededForEmptyLineAfter": () => (/* reexport */ getBreaksNeededForEmptyLineAfter),
17384
- "getBreaksNeededForEmptyLineBefore": () => (/* reexport */ getBreaksNeededForEmptyLineBefore),
17385
- "getCommands": () => (/* reexport */ commands_getCommands),
17386
- "getExtraCommands": () => (/* reexport */ getExtraCommands),
17387
- "getStateFromTextArea": () => (/* reexport */ getStateFromTextArea),
17388
- "getSurroundingWord": () => (/* reexport */ getSurroundingWord),
17389
- "group": () => (/* reexport */ group),
17390
- "hr": () => (/* reexport */ hr),
17391
- "image": () => (/* reexport */ commands_image_image),
17392
- "insertAtLineStart": () => (/* reexport */ insertAtLineStart),
17393
- "insertTextAtPosition": () => (/* reexport */ insertTextAtPosition),
17394
- "italic": () => (/* reexport */ italic),
17395
- "link": () => (/* reexport */ commands_link_link),
17396
- "orderedListCommand": () => (/* reexport */ orderedListCommand),
17397
- "quote": () => (/* reexport */ quote),
17398
- "reducer": () => (/* reexport */ reducer),
17399
- "selectWord": () => (/* reexport */ selectWord),
17400
- "strikethrough": () => (/* reexport */ strikeThrough_strikethrough),
17401
- "title": () => (/* reexport */ title),
17402
- "title1": () => (/* reexport */ title1),
17403
- "title2": () => (/* reexport */ title2),
17404
- "title3": () => (/* reexport */ title3),
17405
- "title4": () => (/* reexport */ title4),
17406
- "title5": () => (/* reexport */ title5),
17407
- "title6": () => (/* reexport */ title6),
17408
- "unorderedListCommand": () => (/* reexport */ unorderedListCommand)
17381
+ divider: () => (/* reexport */ divider),
17382
+ fullscreen: () => (/* reexport */ fullscreen),
17383
+ getBreaksNeededForEmptyLineAfter: () => (/* reexport */ getBreaksNeededForEmptyLineAfter),
17384
+ getBreaksNeededForEmptyLineBefore: () => (/* reexport */ getBreaksNeededForEmptyLineBefore),
17385
+ getCommands: () => (/* reexport */ commands_getCommands),
17386
+ getExtraCommands: () => (/* reexport */ getExtraCommands),
17387
+ getStateFromTextArea: () => (/* reexport */ getStateFromTextArea),
17388
+ getSurroundingWord: () => (/* reexport */ getSurroundingWord),
17389
+ group: () => (/* reexport */ group),
17390
+ hr: () => (/* reexport */ hr),
17391
+ image: () => (/* reexport */ commands_image_image),
17392
+ insertAtLineStart: () => (/* reexport */ insertAtLineStart),
17393
+ insertTextAtPosition: () => (/* reexport */ insertTextAtPosition),
17394
+ italic: () => (/* reexport */ italic),
17395
+ link: () => (/* reexport */ commands_link_link),
17396
+ orderedListCommand: () => (/* reexport */ orderedListCommand),
17397
+ quote: () => (/* reexport */ quote),
17398
+ reducer: () => (/* reexport */ reducer),
17399
+ selectWord: () => (/* reexport */ selectWord),
17400
+ strikethrough: () => (/* reexport */ strikeThrough_strikethrough),
17401
+ title: () => (/* reexport */ title),
17402
+ title1: () => (/* reexport */ title1),
17403
+ title2: () => (/* reexport */ title2),
17404
+ title3: () => (/* reexport */ title3),
17405
+ title4: () => (/* reexport */ title4),
17406
+ title5: () => (/* reexport */ title5),
17407
+ title6: () => (/* reexport */ title6),
17408
+ unorderedListCommand: () => (/* reexport */ unorderedListCommand)
17409
17409
  });
17410
17410
 
17411
17411
  // NAMESPACE OBJECT: ../node_modules/react-markdown/node_modules/micromark/lib/constructs.js
17412
17412
  var constructs_namespaceObject = {};
17413
17413
  __webpack_require__.r(constructs_namespaceObject);
17414
17414
  __webpack_require__.d(constructs_namespaceObject, {
17415
- "attentionMarkers": () => (attentionMarkers),
17416
- "contentInitial": () => (contentInitial),
17417
- "disable": () => (disable),
17418
- "document": () => (constructs_document),
17419
- "flow": () => (constructs_flow),
17420
- "flowInitial": () => (flowInitial),
17421
- "insideSpan": () => (insideSpan),
17422
- "string": () => (constructs_string),
17423
- "text": () => (constructs_text)
17415
+ attentionMarkers: () => (attentionMarkers),
17416
+ contentInitial: () => (contentInitial),
17417
+ disable: () => (disable),
17418
+ document: () => (constructs_document),
17419
+ flow: () => (constructs_flow),
17420
+ flowInitial: () => (flowInitial),
17421
+ insideSpan: () => (insideSpan),
17422
+ string: () => (constructs_string),
17423
+ text: () => (constructs_text)
17424
17424
  });
17425
17425
 
17426
17426
  // NAMESPACE OBJECT: ../node_modules/property-information/lib/util/types.js
17427
17427
  var types_namespaceObject = {};
17428
17428
  __webpack_require__.r(types_namespaceObject);
17429
17429
  __webpack_require__.d(types_namespaceObject, {
17430
- "boolean": () => (types_boolean),
17431
- "booleanish": () => (booleanish),
17432
- "commaOrSpaceSeparated": () => (commaOrSpaceSeparated),
17433
- "commaSeparated": () => (commaSeparated),
17434
- "number": () => (number),
17435
- "overloadedBoolean": () => (overloadedBoolean),
17436
- "spaceSeparated": () => (spaceSeparated)
17430
+ boolean: () => (types_boolean),
17431
+ booleanish: () => (booleanish),
17432
+ commaOrSpaceSeparated: () => (commaOrSpaceSeparated),
17433
+ commaSeparated: () => (commaSeparated),
17434
+ number: () => (number),
17435
+ overloadedBoolean: () => (overloadedBoolean),
17436
+ spaceSeparated: () => (spaceSeparated)
17437
17437
  });
17438
17438
 
17439
17439
  // NAMESPACE OBJECT: ./src/utils/markdownUtils.ts
17440
17440
  var markdownUtils_namespaceObject = {};
17441
17441
  __webpack_require__.r(markdownUtils_namespaceObject);
17442
17442
  __webpack_require__.d(markdownUtils_namespaceObject, {
17443
- "getBreaksNeededForEmptyLineAfter": () => (getBreaksNeededForEmptyLineAfter),
17444
- "getBreaksNeededForEmptyLineBefore": () => (getBreaksNeededForEmptyLineBefore),
17445
- "getSurroundingWord": () => (getSurroundingWord),
17446
- "selectWord": () => (selectWord)
17443
+ getBreaksNeededForEmptyLineAfter: () => (getBreaksNeededForEmptyLineAfter),
17444
+ getBreaksNeededForEmptyLineBefore: () => (getBreaksNeededForEmptyLineBefore),
17445
+ getSurroundingWord: () => (getSurroundingWord),
17446
+ selectWord: () => (selectWord)
17447
17447
  });
17448
17448
 
17449
17449
  // NAMESPACE OBJECT: ./src/commands/index.ts
17450
17450
  var commands_namespaceObject = {};
17451
17451
  __webpack_require__.r(commands_namespaceObject);
17452
17452
  __webpack_require__.d(commands_namespaceObject, {
17453
- "TextAreaCommandOrchestrator": () => (TextAreaCommandOrchestrator),
17454
- "TextAreaTextApi": () => (TextAreaTextApi),
17455
- "bold": () => (bold),
17456
- "checkedListCommand": () => (checkedListCommand),
17457
- "code": () => (code_code),
17458
- "codeBlock": () => (codeBlock),
17459
- "codeEdit": () => (codeEdit),
17460
- "codeLive": () => (codeLive),
17461
- "codePreview": () => (codePreview),
17462
- "comment": () => (commands_comment_comment),
17463
- "divider": () => (divider),
17464
- "fullscreen": () => (fullscreen),
17465
- "getCommands": () => (commands_getCommands),
17466
- "getExtraCommands": () => (getExtraCommands),
17467
- "getStateFromTextArea": () => (getStateFromTextArea),
17468
- "group": () => (group),
17469
- "hr": () => (hr),
17470
- "image": () => (commands_image_image),
17471
- "italic": () => (italic),
17472
- "link": () => (commands_link_link),
17473
- "orderedListCommand": () => (orderedListCommand),
17474
- "quote": () => (quote),
17475
- "strikethrough": () => (strikeThrough_strikethrough),
17476
- "title": () => (title),
17477
- "title1": () => (title1),
17478
- "title2": () => (title2),
17479
- "title3": () => (title3),
17480
- "title4": () => (title4),
17481
- "title5": () => (title5),
17482
- "title6": () => (title6),
17483
- "unorderedListCommand": () => (unorderedListCommand)
17453
+ TextAreaCommandOrchestrator: () => (TextAreaCommandOrchestrator),
17454
+ TextAreaTextApi: () => (TextAreaTextApi),
17455
+ bold: () => (bold),
17456
+ checkedListCommand: () => (checkedListCommand),
17457
+ code: () => (code_code),
17458
+ codeBlock: () => (codeBlock),
17459
+ codeEdit: () => (codeEdit),
17460
+ codeLive: () => (codeLive),
17461
+ codePreview: () => (codePreview),
17462
+ comment: () => (commands_comment_comment),
17463
+ divider: () => (divider),
17464
+ fullscreen: () => (fullscreen),
17465
+ getCommands: () => (commands_getCommands),
17466
+ getExtraCommands: () => (getExtraCommands),
17467
+ getStateFromTextArea: () => (getStateFromTextArea),
17468
+ group: () => (group),
17469
+ hr: () => (hr),
17470
+ image: () => (commands_image_image),
17471
+ italic: () => (italic),
17472
+ link: () => (commands_link_link),
17473
+ orderedListCommand: () => (orderedListCommand),
17474
+ quote: () => (quote),
17475
+ strikethrough: () => (strikeThrough_strikethrough),
17476
+ title: () => (title),
17477
+ title1: () => (title1),
17478
+ title2: () => (title2),
17479
+ title3: () => (title3),
17480
+ title4: () => (title4),
17481
+ title5: () => (title5),
17482
+ title6: () => (title6),
17483
+ unorderedListCommand: () => (unorderedListCommand)
17484
17484
  });
17485
17485
 
17486
17486
  ;// CONCATENATED MODULE: ../node_modules/@babel/runtime/helpers/esm/typeof.js
@@ -28021,7 +28021,10 @@ function defaultOnError(left, right) {
28021
28021
 
28022
28022
 
28023
28023
 
28024
- /** @type {import('unified').Plugin<[Options?] | void[], string, Root>} */
28024
+ /**
28025
+ * @this {import('unified').Processor}
28026
+ * @type {import('unified').Plugin<[Options?] | void[], string, Root>}
28027
+ */
28025
28028
  function remarkParse(options) {
28026
28029
  /** @type {import('unified').ParserFunction<Root>} */
28027
28030
  const parser = (doc) => {
@@ -28043,11 +28046,6 @@ function remarkParse(options) {
28043
28046
  Object.assign(this, {Parser: parser})
28044
28047
  }
28045
28048
 
28046
- ;// CONCATENATED MODULE: ../node_modules/react-markdown/node_modules/remark-parse/index.js
28047
-
28048
-
28049
- /* harmony default export */ const remark_parse = (remarkParse);
28050
-
28051
28049
  ;// CONCATENATED MODULE: ../node_modules/micromark-util-sanitize-uri/index.js
28052
28050
 
28053
28051
 
@@ -33335,7 +33333,7 @@ function ReactMarkdown(options) {
33335
33333
  }
33336
33334
 
33337
33335
  const processor = unified()
33338
- .use(remark_parse)
33336
+ .use(remarkParse)
33339
33337
  .use(options.remarkPlugins || [])
33340
33338
  .use(lib, {
33341
33339
  ...options.remarkRehypeOptions,
@@ -35091,607 +35089,1143 @@ function gfmStrikethrough(options) {
35091
35089
  }
35092
35090
  }
35093
35091
 
35094
- ;// CONCATENATED MODULE: ../node_modules/micromark-extension-gfm-table/lib/syntax.js
35092
+ ;// CONCATENATED MODULE: ../node_modules/micromark-extension-gfm-table/lib/edit-map.js
35095
35093
  /**
35096
- * @typedef {import('micromark-util-types').Extension} Extension
35097
- * @typedef {import('micromark-util-types').Resolver} Resolver
35098
- * @typedef {import('micromark-util-types').Tokenizer} Tokenizer
35099
- * @typedef {import('micromark-util-types').State} State
35100
- * @typedef {import('micromark-util-types').Token} Token
35094
+ * @typedef {import('micromark-util-types').Event} Event
35101
35095
  */
35102
35096
 
35097
+ // Port of `edit_map.rs` from `markdown-rs`.
35098
+ // This should move to `markdown-js` later.
35099
+
35100
+ // Deal with several changes in events, batching them together.
35101
+ //
35102
+ // Preferably, changes should be kept to a minimum.
35103
+ // Sometimes, it’s needed to change the list of events, because parsing can be
35104
+ // messy, and it helps to expose a cleaner interface of events to the compiler
35105
+ // and other users.
35106
+ // It can also help to merge many adjacent similar events.
35107
+ // And, in other cases, it’s needed to parse subcontent: pass some events
35108
+ // through another tokenizer and inject the result.
35109
+
35103
35110
  /**
35104
- * @typedef {'left'|'center'|'right'|'none'} Align
35111
+ * @typedef {[number, number, Array<Event>]} Change
35112
+ * @typedef {[number, number, number]} Jump
35105
35113
  */
35106
35114
 
35115
+ /**
35116
+ * Tracks a bunch of edits.
35117
+ */
35118
+ class EditMap {
35119
+ /**
35120
+ * Create a new edit map.
35121
+ */
35122
+ constructor() {
35123
+ /**
35124
+ * Record of changes.
35125
+ *
35126
+ * @type {Array<Change>}
35127
+ */
35128
+ this.map = []
35129
+ }
35107
35130
 
35131
+ /**
35132
+ * Create an edit: a remove and/or add at a certain place.
35133
+ *
35134
+ * @param {number} index
35135
+ * @param {number} remove
35136
+ * @param {Array<Event>} add
35137
+ * @returns {void}
35138
+ */
35139
+ add(index, remove, add) {
35140
+ addImpl(this, index, remove, add)
35141
+ }
35142
+
35143
+ // To do: not used here.
35144
+ // /**
35145
+ // * Create an edit: but insert `add` before existing additions.
35146
+ // *
35147
+ // * @param {number} index
35148
+ // * @param {number} remove
35149
+ // * @param {Array<Event>} add
35150
+ // * @returns {void}
35151
+ // */
35152
+ // addBefore(index, remove, add) {
35153
+ // addImpl(this, index, remove, add, true)
35154
+ // }
35108
35155
 
35109
- /** @type {Extension} */
35110
- const gfmTable = {
35111
- flow: {
35112
- null: {
35113
- tokenize: tokenizeTable,
35114
- resolve: resolveTable
35156
+ /**
35157
+ * Done, change the events.
35158
+ *
35159
+ * @param {Array<Event>} events
35160
+ * @returns {void}
35161
+ */
35162
+ consume(events) {
35163
+ this.map.sort((a, b) => a[0] - b[0])
35164
+
35165
+ /* c8 ignore next 3 -- `resolve` is never called without tables, so without edits. */
35166
+ if (this.map.length === 0) {
35167
+ return
35115
35168
  }
35116
- }
35117
- }
35118
- const nextPrefixedOrBlank = {
35119
- tokenize: tokenizeNextPrefixedOrBlank,
35120
- partial: true
35121
- }
35122
- /** @type {Resolver} */
35123
35169
 
35124
- function resolveTable(events, context) {
35125
- let index = -1
35126
- /** @type {boolean|undefined} */
35170
+ // To do: if links are added in events, like they are in `markdown-rs`,
35171
+ // this is needed.
35172
+ // // Calculate jumps: where items in the current list move to.
35173
+ // /** @type {Array<Jump>} */
35174
+ // const jumps = []
35175
+ // let index = 0
35176
+ // let addAcc = 0
35177
+ // let removeAcc = 0
35178
+ // while (index < this.map.length) {
35179
+ // const [at, remove, add] = this.map[index]
35180
+ // removeAcc += remove
35181
+ // addAcc += add.length
35182
+ // jumps.push([at, removeAcc, addAcc])
35183
+ // index += 1
35184
+ // }
35185
+ //
35186
+ // . shiftLinks(events, jumps)
35127
35187
 
35128
- let inHead
35129
- /** @type {boolean|undefined} */
35188
+ let index = this.map.length
35189
+ /** @type {Array<Array<Event>>} */
35190
+ const vecs = []
35191
+ while (index > 0) {
35192
+ index -= 1
35193
+ vecs.push(events.slice(this.map[index][0] + this.map[index][1]))
35194
+ // eslint-disable-next-line unicorn/no-array-push-push
35195
+ vecs.push(this.map[index][2])
35130
35196
 
35131
- let inDelimiterRow
35132
- /** @type {boolean|undefined} */
35197
+ // Truncate rest.
35198
+ events.length = this.map[index][0]
35199
+ }
35200
+ vecs.push([...events])
35201
+ events.length = 0
35202
+ let slice = vecs.pop()
35203
+ while (slice) {
35204
+ events.push(...slice)
35205
+ slice = vecs.pop()
35206
+ }
35133
35207
 
35134
- let inRow
35135
- /** @type {number|undefined} */
35208
+ // Truncate everything.
35209
+ this.map.length = 0
35210
+ }
35211
+ }
35136
35212
 
35137
- let contentStart
35138
- /** @type {number|undefined} */
35213
+ /**
35214
+ * Create an edit.
35215
+ *
35216
+ * @param {EditMap} editMap
35217
+ * @param {number} at
35218
+ * @param {number} remove
35219
+ * @param {Array<Event>} add
35220
+ * @returns {void}
35221
+ */
35222
+ function addImpl(editMap, at, remove, add) {
35223
+ let index = 0
35139
35224
 
35140
- let contentEnd
35141
- /** @type {number|undefined} */
35225
+ /* c8 ignore next 3 -- `resolve` is never called without tables, so without edits. */
35226
+ if (remove === 0 && add.length === 0) {
35227
+ return
35228
+ }
35229
+ while (index < editMap.map.length) {
35230
+ if (editMap.map[index][0] === at) {
35231
+ editMap.map[index][1] += remove
35142
35232
 
35143
- let cellStart
35144
- /** @type {boolean|undefined} */
35233
+ // To do: before not used.
35234
+ // if (before) {
35235
+ // add.push(...editMap.map[index][2])
35236
+ // editMap.map[index][2] = add
35237
+ // } else {
35238
+ editMap.map[index][2].push(...add)
35239
+ // }
35145
35240
 
35146
- let seenCellInRow
35241
+ return
35242
+ }
35243
+ index += 1
35244
+ }
35245
+ editMap.map.push([at, remove, add])
35246
+ }
35247
+
35248
+ // /**
35249
+ // * Shift `previous` and `next` links according to `jumps`.
35250
+ // *
35251
+ // * This fixes links in case there are events removed or added between them.
35252
+ // *
35253
+ // * @param {Array<Event>} events
35254
+ // * @param {Array<Jump>} jumps
35255
+ // */
35256
+ // function shiftLinks(events, jumps) {
35257
+ // let jumpIndex = 0
35258
+ // let index = 0
35259
+ // let add = 0
35260
+ // let rm = 0
35261
+
35262
+ // while (index < events.length) {
35263
+ // const rmCurr = rm
35264
+
35265
+ // while (jumpIndex < jumps.length && jumps[jumpIndex][0] <= index) {
35266
+ // add = jumps[jumpIndex][2]
35267
+ // rm = jumps[jumpIndex][1]
35268
+ // jumpIndex += 1
35269
+ // }
35270
+
35271
+ // // Ignore items that will be removed.
35272
+ // if (rm > rmCurr) {
35273
+ // index += rm - rmCurr
35274
+ // } else {
35275
+ // console.log('to do: links?', add, rmCurr)
35276
+ // // ?
35277
+ // // if let Some(link) = &events[index].link {
35278
+ // // if let Some(next) = link.next {
35279
+ // // events[next].link.as_mut().unwrap().previous = Some(index + add - rm);
35280
+ // // while jumpIndex < jumps.len() && jumps[jumpIndex].0 <= next {
35281
+ // // add = jumps[jumpIndex].2;
35282
+ // // rm = jumps[jumpIndex].1;
35283
+ // // jumpIndex += 1;
35284
+ // // }
35285
+ // // events[index].link.as_mut().unwrap().next = Some(next + add - rm);
35286
+ // // index = next;
35287
+ // // continue;
35288
+ // // }
35289
+ // // }
35290
+ // index += 1
35291
+ // }
35292
+ // }
35293
+ // }
35294
+
35295
+ ;// CONCATENATED MODULE: ../node_modules/micromark-extension-gfm-table/lib/infer.js
35296
+ /**
35297
+ * @typedef {import('micromark-util-types').Event} Event
35298
+ */
35147
35299
 
35148
- while (++index < events.length) {
35149
- const token = events[index][1]
35300
+ /**
35301
+ * @typedef {'left' | 'center' | 'right' | 'none'} Align
35302
+ */
35150
35303
 
35151
- if (inRow) {
35152
- if (token.type === 'temporaryTableCellContent') {
35153
- contentStart = contentStart || index
35154
- contentEnd = index
35304
+ /**
35305
+ * Figure out the alignment of a GFM table.
35306
+ *
35307
+ * @param {Array<Event>} events
35308
+ * @param {number} index
35309
+ * @returns {Array<Align>}
35310
+ */
35311
+ function gfmTableAlign(events, index) {
35312
+ let inDelimiterRow = false
35313
+ /** @type {Array<Align>} */
35314
+ const align = []
35315
+ while (index < events.length) {
35316
+ const event = events[index]
35317
+ if (inDelimiterRow) {
35318
+ if (event[0] === 'enter') {
35319
+ // Start of alignment value: set a new column.
35320
+ // To do: `markdown-rs` uses `tableDelimiterCellValue`.
35321
+ if (event[1].type === 'tableContent') {
35322
+ align.push(
35323
+ events[index + 1][1].type === 'tableDelimiterMarker'
35324
+ ? 'left'
35325
+ : 'none'
35326
+ )
35327
+ }
35155
35328
  }
35156
-
35157
- if (
35158
- // Combine separate content parts into one.
35159
- (token.type === 'tableCellDivider' || token.type === 'tableRow') &&
35160
- contentEnd
35161
- ) {
35162
- const content = {
35163
- type: 'tableContent',
35164
- start: events[contentStart][1].start,
35165
- end: events[contentEnd][1].end
35166
- }
35167
- /** @type {Token} */
35168
-
35169
- const text = {
35170
- type: 'chunkText',
35171
- start: content.start,
35172
- end: content.end,
35173
- // @ts-expect-error It’s fine.
35174
- contentType: 'text'
35175
- }
35176
- events.splice(
35177
- contentStart,
35178
- contentEnd - contentStart + 1,
35179
- ['enter', content, context],
35180
- ['enter', text, context],
35181
- ['exit', text, context],
35182
- ['exit', content, context]
35183
- )
35184
- index -= contentEnd - contentStart - 3
35185
- contentStart = undefined
35186
- contentEnd = undefined
35329
+ // Exits:
35330
+ // End of alignment value: change the column.
35331
+ // To do: `markdown-rs` uses `tableDelimiterCellValue`.
35332
+ else if (event[1].type === 'tableContent') {
35333
+ if (events[index - 1][1].type === 'tableDelimiterMarker') {
35334
+ const alignIndex = align.length - 1
35335
+ align[alignIndex] = align[alignIndex] === 'left' ? 'center' : 'right'
35336
+ }
35337
+ }
35338
+ // Done!
35339
+ else if (event[1].type === 'tableDelimiterRow') {
35340
+ break
35187
35341
  }
35342
+ } else if (event[0] === 'enter' && event[1].type === 'tableDelimiterRow') {
35343
+ inDelimiterRow = true
35188
35344
  }
35345
+ index += 1
35346
+ }
35347
+ return align
35348
+ }
35189
35349
 
35190
- if (
35191
- events[index][0] === 'exit' &&
35192
- cellStart !== undefined &&
35193
- cellStart + (seenCellInRow ? 0 : 1) < index &&
35194
- (token.type === 'tableCellDivider' ||
35195
- (token.type === 'tableRow' &&
35196
- (cellStart + 3 < index ||
35197
- events[cellStart][1].type !== 'whitespace')))
35198
- ) {
35199
- const cell = {
35200
- type: inDelimiterRow
35201
- ? 'tableDelimiter'
35202
- : inHead
35203
- ? 'tableHeader'
35204
- : 'tableData',
35205
- start: events[cellStart][1].start,
35206
- end: events[index][1].end
35207
- }
35208
- events.splice(index + (token.type === 'tableCellDivider' ? 1 : 0), 0, [
35209
- 'exit',
35210
- cell,
35211
- context
35212
- ])
35213
- events.splice(cellStart, 0, ['enter', cell, context])
35214
- index += 2
35215
- cellStart = index + 1
35216
- seenCellInRow = true
35217
- }
35350
+ ;// CONCATENATED MODULE: ../node_modules/micromark-extension-gfm-table/lib/syntax.js
35351
+ /**
35352
+ * @typedef {import('micromark-util-types').Event} Event
35353
+ * @typedef {import('micromark-util-types').Extension} Extension
35354
+ * @typedef {import('micromark-util-types').Point} Point
35355
+ * @typedef {import('micromark-util-types').Resolver} Resolver
35356
+ * @typedef {import('micromark-util-types').State} State
35357
+ * @typedef {import('micromark-util-types').Token} Token
35358
+ * @typedef {import('micromark-util-types').TokenizeContext} TokenizeContext
35359
+ * @typedef {import('micromark-util-types').Tokenizer} Tokenizer
35360
+ */
35218
35361
 
35219
- if (token.type === 'tableRow') {
35220
- inRow = events[index][0] === 'enter'
35362
+ /**
35363
+ * @typedef {[number, number, number, number]} Range
35364
+ * Cell info.
35365
+ *
35366
+ * @typedef {0 | 1 | 2 | 3} RowKind
35367
+ * Where we are: `1` for head row, `2` for delimiter row, `3` for body row.
35368
+ */
35221
35369
 
35222
- if (inRow) {
35223
- cellStart = index + 1
35224
- seenCellInRow = false
35225
- }
35226
- }
35227
35370
 
35228
- if (token.type === 'tableDelimiterRow') {
35229
- inDelimiterRow = events[index][0] === 'enter'
35230
35371
 
35231
- if (inDelimiterRow) {
35232
- cellStart = index + 1
35233
- seenCellInRow = false
35234
- }
35235
- }
35236
35372
 
35237
- if (token.type === 'tableHead') {
35238
- inHead = events[index][0] === 'enter'
35373
+
35374
+
35375
+ // To do: next major: expose functions.
35376
+
35377
+ /**
35378
+ * Extension for `micromark` that can be passed in `extensions` to enable GFM
35379
+ * table syntax.
35380
+ *
35381
+ * @type {Extension}
35382
+ */
35383
+ const gfmTable = {
35384
+ flow: {
35385
+ null: {
35386
+ tokenize: tokenizeTable,
35387
+ resolveAll: resolveTable
35239
35388
  }
35240
35389
  }
35241
-
35242
- return events
35243
35390
  }
35244
- /** @type {Tokenizer} */
35245
35391
 
35392
+ /**
35393
+ * @this {TokenizeContext}
35394
+ * @type {Tokenizer}
35395
+ */
35246
35396
  function tokenizeTable(effects, ok, nok) {
35247
35397
  const self = this
35248
- /** @type {Array<Align>} */
35249
-
35250
- const align = []
35251
- let tableHeaderCount = 0
35252
- /** @type {boolean|undefined} */
35253
-
35254
- let seenDelimiter
35255
- /** @type {boolean|undefined} */
35256
-
35257
- let hasDash
35398
+ let size = 0
35399
+ let sizeB = 0
35400
+ /** @type {boolean | undefined} */
35401
+ let seen
35258
35402
  return start
35259
- /** @type {State} */
35260
35403
 
35404
+ /**
35405
+ * Start of a GFM table.
35406
+ *
35407
+ * If there is a valid table row or table head before, then we try to parse
35408
+ * another row.
35409
+ * Otherwise, we try to parse a head.
35410
+ *
35411
+ * ```markdown
35412
+ * > | | a |
35413
+ * ^
35414
+ * | | - |
35415
+ * > | | b |
35416
+ * ^
35417
+ * ```
35418
+ * @type {State}
35419
+ */
35261
35420
  function start(code) {
35262
- // @ts-expect-error Custom.
35263
- effects.enter('table')._align = align
35421
+ let index = self.events.length - 1
35422
+ while (index > -1) {
35423
+ const type = self.events[index][1].type
35424
+ if (
35425
+ type === 'lineEnding' ||
35426
+ // Note: markdown-rs uses `whitespace` instead of `linePrefix`
35427
+ type === 'linePrefix'
35428
+ )
35429
+ index--
35430
+ else break
35431
+ }
35432
+ const tail = index > -1 ? self.events[index][1].type : null
35433
+ const next =
35434
+ tail === 'tableHead' || tail === 'tableRow' ? bodyRowStart : headRowBefore
35435
+
35436
+ // Don’t allow lazy body rows.
35437
+ if (next === bodyRowStart && self.parser.lazy[self.now().line]) {
35438
+ return nok(code)
35439
+ }
35440
+ return next(code)
35441
+ }
35442
+
35443
+ /**
35444
+ * Before table head row.
35445
+ *
35446
+ * ```markdown
35447
+ * > | | a |
35448
+ * ^
35449
+ * | | - |
35450
+ * | | b |
35451
+ * ```
35452
+ *
35453
+ * @type {State}
35454
+ */
35455
+ function headRowBefore(code) {
35264
35456
  effects.enter('tableHead')
35265
- effects.enter('tableRow') // If we start with a pipe, we open a cell marker.
35457
+ effects.enter('tableRow')
35458
+ return headRowStart(code)
35459
+ }
35266
35460
 
35461
+ /**
35462
+ * Before table head row, after whitespace.
35463
+ *
35464
+ * ```markdown
35465
+ * > | | a |
35466
+ * ^
35467
+ * | | - |
35468
+ * | | b |
35469
+ * ```
35470
+ *
35471
+ * @type {State}
35472
+ */
35473
+ function headRowStart(code) {
35267
35474
  if (code === 124) {
35268
- return cellDividerHead(code)
35475
+ return headRowBreak(code)
35269
35476
  }
35270
35477
 
35271
- tableHeaderCount++
35272
- effects.enter('temporaryTableCellContent') // Can’t be space or eols at the start of a construct, so we’re in a cell.
35273
-
35274
- return inCellContentHead(code)
35275
- }
35276
- /** @type {State} */
35478
+ // To do: micromark-js should let us parse our own whitespace in extensions,
35479
+ // like `markdown-rs`:
35480
+ //
35481
+ // ```js
35482
+ // // 4+ spaces.
35483
+ // if (markdownSpace(code)) {
35484
+ // return nok(code)
35485
+ // }
35486
+ // ```
35277
35487
 
35278
- function cellDividerHead(code) {
35279
- effects.enter('tableCellDivider')
35280
- effects.consume(code)
35281
- effects.exit('tableCellDivider')
35282
- seenDelimiter = true
35283
- return cellBreakHead
35488
+ seen = true
35489
+ // Count the first character, that isn’t a pipe, double.
35490
+ sizeB += 1
35491
+ return headRowBreak(code)
35284
35492
  }
35285
- /** @type {State} */
35286
35493
 
35287
- function cellBreakHead(code) {
35288
- if (code === null || markdownLineEnding(code)) {
35289
- return atRowEndHead(code)
35494
+ /**
35495
+ * At break in table head row.
35496
+ *
35497
+ * ```markdown
35498
+ * > | | a |
35499
+ * ^
35500
+ * ^
35501
+ * ^
35502
+ * | | - |
35503
+ * | | b |
35504
+ * ```
35505
+ *
35506
+ * @type {State}
35507
+ */
35508
+ function headRowBreak(code) {
35509
+ if (code === null) {
35510
+ // Note: in `markdown-rs`, we need to reset, in `micromark-js` we don‘t.
35511
+ return nok(code)
35290
35512
  }
35513
+ if (markdownLineEnding(code)) {
35514
+ // If anything other than one pipe (ignoring whitespace) was used, it’s fine.
35515
+ if (sizeB > 1) {
35516
+ sizeB = 0
35517
+ // To do: check if this works.
35518
+ // Feel free to interrupt:
35519
+ self.interrupt = true
35520
+ effects.exit('tableRow')
35521
+ effects.enter('lineEnding')
35522
+ effects.consume(code)
35523
+ effects.exit('lineEnding')
35524
+ return headDelimiterStart
35525
+ }
35291
35526
 
35527
+ // Note: in `markdown-rs`, we need to reset, in `micromark-js` we don‘t.
35528
+ return nok(code)
35529
+ }
35292
35530
  if (markdownSpace(code)) {
35293
- effects.enter('whitespace')
35294
- effects.consume(code)
35295
- return inWhitespaceHead
35531
+ // To do: check if this is fine.
35532
+ // effects.attempt(State::Next(StateName::GfmTableHeadRowBreak), State::Nok)
35533
+ // State::Retry(space_or_tab(tokenizer))
35534
+ return factorySpace(effects, headRowBreak, 'whitespace')(code)
35296
35535
  }
35297
-
35298
- if (seenDelimiter) {
35299
- seenDelimiter = undefined
35300
- tableHeaderCount++
35536
+ sizeB += 1
35537
+ if (seen) {
35538
+ seen = false
35539
+ // Header cell count.
35540
+ size += 1
35301
35541
  }
35302
-
35303
35542
  if (code === 124) {
35304
- return cellDividerHead(code)
35305
- } // Anything else is cell content.
35306
-
35307
- effects.enter('temporaryTableCellContent')
35308
- return inCellContentHead(code)
35309
- }
35310
- /** @type {State} */
35311
-
35312
- function inWhitespaceHead(code) {
35313
- if (markdownSpace(code)) {
35543
+ effects.enter('tableCellDivider')
35314
35544
  effects.consume(code)
35315
- return inWhitespaceHead
35545
+ effects.exit('tableCellDivider')
35546
+ // Whether a delimiter was seen.
35547
+ seen = true
35548
+ return headRowBreak
35316
35549
  }
35317
35550
 
35318
- effects.exit('whitespace')
35319
- return cellBreakHead(code)
35551
+ // Anything else is cell data.
35552
+ effects.enter('data')
35553
+ return headRowData(code)
35320
35554
  }
35321
- /** @type {State} */
35322
35555
 
35323
- function inCellContentHead(code) {
35324
- // EOF, whitespace, pipe
35556
+ /**
35557
+ * In table head row data.
35558
+ *
35559
+ * ```markdown
35560
+ * > | | a |
35561
+ * ^
35562
+ * | | - |
35563
+ * | | b |
35564
+ * ```
35565
+ *
35566
+ * @type {State}
35567
+ */
35568
+ function headRowData(code) {
35325
35569
  if (code === null || code === 124 || markdownLineEndingOrSpace(code)) {
35326
- effects.exit('temporaryTableCellContent')
35327
- return cellBreakHead(code)
35570
+ effects.exit('data')
35571
+ return headRowBreak(code)
35328
35572
  }
35329
-
35330
35573
  effects.consume(code)
35331
- return code === 92 ? inCellContentEscapeHead : inCellContentHead
35574
+ return code === 92 ? headRowEscape : headRowData
35332
35575
  }
35333
- /** @type {State} */
35334
35576
 
35335
- function inCellContentEscapeHead(code) {
35577
+ /**
35578
+ * In table head row escape.
35579
+ *
35580
+ * ```markdown
35581
+ * > | | a\-b |
35582
+ * ^
35583
+ * | | ---- |
35584
+ * | | c |
35585
+ * ```
35586
+ *
35587
+ * @type {State}
35588
+ */
35589
+ function headRowEscape(code) {
35336
35590
  if (code === 92 || code === 124) {
35337
35591
  effects.consume(code)
35338
- return inCellContentHead
35339
- } // Anything else.
35340
-
35341
- return inCellContentHead(code)
35342
- }
35343
- /** @type {State} */
35344
-
35345
- function atRowEndHead(code) {
35346
- if (code === null) {
35347
- return nok(code)
35592
+ return headRowData
35348
35593
  }
35349
-
35350
- effects.exit('tableRow')
35351
- effects.exit('tableHead')
35352
- const originalInterrupt = self.interrupt
35353
- self.interrupt = true
35354
- return effects.attempt(
35355
- {
35356
- tokenize: tokenizeRowEnd,
35357
- partial: true
35358
- },
35359
- function (code) {
35360
- self.interrupt = originalInterrupt
35361
- effects.enter('tableDelimiterRow')
35362
- return atDelimiterRowBreak(code)
35363
- },
35364
- function (code) {
35365
- self.interrupt = originalInterrupt
35366
- return nok(code)
35367
- }
35368
- )(code)
35594
+ return headRowData(code)
35369
35595
  }
35370
- /** @type {State} */
35371
35596
 
35372
- function atDelimiterRowBreak(code) {
35373
- if (code === null || markdownLineEnding(code)) {
35374
- return rowEndDelimiter(code)
35375
- }
35597
+ /**
35598
+ * Before delimiter row.
35599
+ *
35600
+ * ```markdown
35601
+ * | | a |
35602
+ * > | | - |
35603
+ * ^
35604
+ * | | b |
35605
+ * ```
35606
+ *
35607
+ * @type {State}
35608
+ */
35609
+ function headDelimiterStart(code) {
35610
+ // Reset `interrupt`.
35611
+ self.interrupt = false
35376
35612
 
35613
+ // Note: in `markdown-rs`, we need to handle piercing here too.
35614
+ if (self.parser.lazy[self.now().line]) {
35615
+ return nok(code)
35616
+ }
35617
+ effects.enter('tableDelimiterRow')
35618
+ // Track if we’ve seen a `:` or `|`.
35619
+ seen = false
35377
35620
  if (markdownSpace(code)) {
35378
- effects.enter('whitespace')
35379
- effects.consume(code)
35380
- return inWhitespaceDelimiter
35621
+ return factorySpace(
35622
+ effects,
35623
+ headDelimiterBefore,
35624
+ 'linePrefix',
35625
+ self.parser.constructs.disable.null.includes('codeIndented')
35626
+ ? undefined
35627
+ : 4
35628
+ )(code)
35381
35629
  }
35630
+ return headDelimiterBefore(code)
35631
+ }
35382
35632
 
35383
- if (code === 45) {
35384
- effects.enter('tableDelimiterFiller')
35385
- effects.consume(code)
35386
- hasDash = true
35387
- align.push('none')
35388
- return inFillerDelimiter
35633
+ /**
35634
+ * Before delimiter row, after optional whitespace.
35635
+ *
35636
+ * Reused when a `|` is found later, to parse another cell.
35637
+ *
35638
+ * ```markdown
35639
+ * | | a |
35640
+ * > | | - |
35641
+ * ^
35642
+ * | | b |
35643
+ * ```
35644
+ *
35645
+ * @type {State}
35646
+ */
35647
+ function headDelimiterBefore(code) {
35648
+ if (code === 45 || code === 58) {
35649
+ return headDelimiterValueBefore(code)
35389
35650
  }
35390
-
35391
- if (code === 58) {
35392
- effects.enter('tableDelimiterAlignment')
35393
- effects.consume(code)
35394
- effects.exit('tableDelimiterAlignment')
35395
- align.push('left')
35396
- return afterLeftAlignment
35397
- } // If we start with a pipe, we open a cell marker.
35398
-
35399
35651
  if (code === 124) {
35652
+ seen = true
35653
+ // If we start with a pipe, we open a cell marker.
35400
35654
  effects.enter('tableCellDivider')
35401
35655
  effects.consume(code)
35402
35656
  effects.exit('tableCellDivider')
35403
- return atDelimiterRowBreak
35657
+ return headDelimiterCellBefore
35404
35658
  }
35405
35659
 
35406
- return nok(code)
35660
+ // More whitespace / empty row not allowed at start.
35661
+ return headDelimiterNok(code)
35407
35662
  }
35408
- /** @type {State} */
35409
35663
 
35410
- function inWhitespaceDelimiter(code) {
35664
+ /**
35665
+ * After `|`, before delimiter cell.
35666
+ *
35667
+ * ```markdown
35668
+ * | | a |
35669
+ * > | | - |
35670
+ * ^
35671
+ * ```
35672
+ *
35673
+ * @type {State}
35674
+ */
35675
+ function headDelimiterCellBefore(code) {
35411
35676
  if (markdownSpace(code)) {
35412
- effects.consume(code)
35413
- return inWhitespaceDelimiter
35677
+ return factorySpace(effects, headDelimiterValueBefore, 'whitespace')(code)
35414
35678
  }
35415
-
35416
- effects.exit('whitespace')
35417
- return atDelimiterRowBreak(code)
35679
+ return headDelimiterValueBefore(code)
35418
35680
  }
35419
- /** @type {State} */
35420
-
35421
- function inFillerDelimiter(code) {
35422
- if (code === 45) {
35423
- effects.consume(code)
35424
- return inFillerDelimiter
35425
- }
35426
-
35427
- effects.exit('tableDelimiterFiller')
35428
35681
 
35682
+ /**
35683
+ * Before delimiter cell value.
35684
+ *
35685
+ * ```markdown
35686
+ * | | a |
35687
+ * > | | - |
35688
+ * ^
35689
+ * ```
35690
+ *
35691
+ * @type {State}
35692
+ */
35693
+ function headDelimiterValueBefore(code) {
35694
+ // Align: left.
35429
35695
  if (code === 58) {
35430
- effects.enter('tableDelimiterAlignment')
35696
+ sizeB += 1
35697
+ seen = true
35698
+ effects.enter('tableDelimiterMarker')
35431
35699
  effects.consume(code)
35432
- effects.exit('tableDelimiterAlignment')
35433
- align[align.length - 1] =
35434
- align[align.length - 1] === 'left' ? 'center' : 'right'
35435
- return afterRightAlignment
35700
+ effects.exit('tableDelimiterMarker')
35701
+ return headDelimiterLeftAlignmentAfter
35436
35702
  }
35437
35703
 
35438
- return atDelimiterRowBreak(code)
35704
+ // Align: none.
35705
+ if (code === 45) {
35706
+ sizeB += 1
35707
+ // To do: seems weird that this *isn’t* left aligned, but that state is used?
35708
+ return headDelimiterLeftAlignmentAfter(code)
35709
+ }
35710
+ if (code === null || markdownLineEnding(code)) {
35711
+ return headDelimiterCellAfter(code)
35712
+ }
35713
+ return headDelimiterNok(code)
35439
35714
  }
35440
- /** @type {State} */
35441
35715
 
35442
- function afterLeftAlignment(code) {
35716
+ /**
35717
+ * After delimiter cell left alignment marker.
35718
+ *
35719
+ * ```markdown
35720
+ * | | a |
35721
+ * > | | :- |
35722
+ * ^
35723
+ * ```
35724
+ *
35725
+ * @type {State}
35726
+ */
35727
+ function headDelimiterLeftAlignmentAfter(code) {
35443
35728
  if (code === 45) {
35444
35729
  effects.enter('tableDelimiterFiller')
35445
- effects.consume(code)
35446
- hasDash = true
35447
- return inFillerDelimiter
35448
- } // Anything else is not ok.
35730
+ return headDelimiterFiller(code)
35731
+ }
35449
35732
 
35450
- return nok(code)
35733
+ // Anything else is not ok after the left-align colon.
35734
+ return headDelimiterNok(code)
35451
35735
  }
35452
- /** @type {State} */
35453
-
35454
- function afterRightAlignment(code) {
35455
- if (code === null || markdownLineEnding(code)) {
35456
- return rowEndDelimiter(code)
35457
- }
35458
35736
 
35459
- if (markdownSpace(code)) {
35460
- effects.enter('whitespace')
35737
+ /**
35738
+ * In delimiter cell filler.
35739
+ *
35740
+ * ```markdown
35741
+ * | | a |
35742
+ * > | | - |
35743
+ * ^
35744
+ * ```
35745
+ *
35746
+ * @type {State}
35747
+ */
35748
+ function headDelimiterFiller(code) {
35749
+ if (code === 45) {
35461
35750
  effects.consume(code)
35462
- return inWhitespaceDelimiter
35463
- } // `|`
35751
+ return headDelimiterFiller
35752
+ }
35464
35753
 
35465
- if (code === 124) {
35466
- effects.enter('tableCellDivider')
35754
+ // Align is `center` if it was `left`, `right` otherwise.
35755
+ if (code === 58) {
35756
+ seen = true
35757
+ effects.exit('tableDelimiterFiller')
35758
+ effects.enter('tableDelimiterMarker')
35467
35759
  effects.consume(code)
35468
- effects.exit('tableCellDivider')
35469
- return atDelimiterRowBreak
35760
+ effects.exit('tableDelimiterMarker')
35761
+ return headDelimiterRightAlignmentAfter
35470
35762
  }
35471
-
35472
- return nok(code)
35763
+ effects.exit('tableDelimiterFiller')
35764
+ return headDelimiterRightAlignmentAfter(code)
35473
35765
  }
35474
- /** @type {State} */
35475
35766
 
35476
- function rowEndDelimiter(code) {
35477
- effects.exit('tableDelimiterRow') // Exit if there was no dash at all, or if the header cell count is not the
35478
- // delimiter cell count.
35479
-
35480
- if (!hasDash || tableHeaderCount !== align.length) {
35481
- return nok(code)
35767
+ /**
35768
+ * After delimiter cell right alignment marker.
35769
+ *
35770
+ * ```markdown
35771
+ * | | a |
35772
+ * > | | -: |
35773
+ * ^
35774
+ * ```
35775
+ *
35776
+ * @type {State}
35777
+ */
35778
+ function headDelimiterRightAlignmentAfter(code) {
35779
+ if (markdownSpace(code)) {
35780
+ return factorySpace(effects, headDelimiterCellAfter, 'whitespace')(code)
35482
35781
  }
35782
+ return headDelimiterCellAfter(code)
35783
+ }
35483
35784
 
35484
- if (code === null) {
35485
- return tableClose(code)
35785
+ /**
35786
+ * After delimiter cell.
35787
+ *
35788
+ * ```markdown
35789
+ * | | a |
35790
+ * > | | -: |
35791
+ * ^
35792
+ * ```
35793
+ *
35794
+ * @type {State}
35795
+ */
35796
+ function headDelimiterCellAfter(code) {
35797
+ if (code === 124) {
35798
+ return headDelimiterBefore(code)
35486
35799
  }
35487
-
35488
- return effects.check(
35489
- nextPrefixedOrBlank,
35490
- tableClose,
35491
- effects.attempt(
35492
- {
35493
- tokenize: tokenizeRowEnd,
35494
- partial: true
35495
- },
35496
- factorySpace(effects, bodyStart, 'linePrefix', 4),
35497
- tableClose
35498
- )
35499
- )(code)
35800
+ if (code === null || markdownLineEnding(code)) {
35801
+ // Exit when:
35802
+ // * there was no `:` or `|` at all (it’s a thematic break or setext
35803
+ // underline instead)
35804
+ // * the header cell count is not the delimiter cell count
35805
+ if (!seen || size !== sizeB) {
35806
+ return headDelimiterNok(code)
35807
+ }
35808
+
35809
+ // Note: in markdown-rs`, a reset is needed here.
35810
+ effects.exit('tableDelimiterRow')
35811
+ effects.exit('tableHead')
35812
+ // To do: in `markdown-rs`, resolvers need to be registered manually.
35813
+ // effects.register_resolver(ResolveName::GfmTable)
35814
+ return ok(code)
35815
+ }
35816
+ return headDelimiterNok(code)
35500
35817
  }
35501
- /** @type {State} */
35502
35818
 
35503
- function tableClose(code) {
35504
- effects.exit('table')
35505
- return ok(code)
35819
+ /**
35820
+ * In delimiter row, at a disallowed byte.
35821
+ *
35822
+ * ```markdown
35823
+ * | | a |
35824
+ * > | | x |
35825
+ * ^
35826
+ * ```
35827
+ *
35828
+ * @type {State}
35829
+ */
35830
+ function headDelimiterNok(code) {
35831
+ // Note: in `markdown-rs`, we need to reset, in `micromark-js` we don‘t.
35832
+ return nok(code)
35506
35833
  }
35507
- /** @type {State} */
35508
35834
 
35509
- function bodyStart(code) {
35510
- effects.enter('tableBody')
35511
- return rowStartBody(code)
35835
+ /**
35836
+ * Before table body row.
35837
+ *
35838
+ * ```markdown
35839
+ * | | a |
35840
+ * | | - |
35841
+ * > | | b |
35842
+ * ^
35843
+ * ```
35844
+ *
35845
+ * @type {State}
35846
+ */
35847
+ function bodyRowStart(code) {
35848
+ // Note: in `markdown-rs` we need to manually take care of a prefix,
35849
+ // but in `micromark-js` that is done for us, so if we’re here, we’re
35850
+ // never at whitespace.
35851
+ effects.enter('tableRow')
35852
+ return bodyRowBreak(code)
35512
35853
  }
35513
- /** @type {State} */
35514
-
35515
- function rowStartBody(code) {
35516
- effects.enter('tableRow') // If we start with a pipe, we open a cell marker.
35517
35854
 
35855
+ /**
35856
+ * At break in table body row.
35857
+ *
35858
+ * ```markdown
35859
+ * | | a |
35860
+ * | | - |
35861
+ * > | | b |
35862
+ * ^
35863
+ * ^
35864
+ * ^
35865
+ * ```
35866
+ *
35867
+ * @type {State}
35868
+ */
35869
+ function bodyRowBreak(code) {
35518
35870
  if (code === 124) {
35519
- return cellDividerBody(code)
35871
+ effects.enter('tableCellDivider')
35872
+ effects.consume(code)
35873
+ effects.exit('tableCellDivider')
35874
+ return bodyRowBreak
35520
35875
  }
35521
-
35522
- effects.enter('temporaryTableCellContent') // Can’t be space or eols at the start of a construct, so we’re in a cell.
35523
-
35524
- return inCellContentBody(code)
35525
- }
35526
- /** @type {State} */
35527
-
35528
- function cellDividerBody(code) {
35529
- effects.enter('tableCellDivider')
35530
- effects.consume(code)
35531
- effects.exit('tableCellDivider')
35532
- return cellBreakBody
35533
- }
35534
- /** @type {State} */
35535
-
35536
- function cellBreakBody(code) {
35537
35876
  if (code === null || markdownLineEnding(code)) {
35538
- return atRowEndBody(code)
35877
+ effects.exit('tableRow')
35878
+ return ok(code)
35539
35879
  }
35540
-
35541
- if (markdownSpace(code)) {
35542
- effects.enter('whitespace')
35543
- effects.consume(code)
35544
- return inWhitespaceBody
35545
- } // `|`
35546
-
35547
- if (code === 124) {
35548
- return cellDividerBody(code)
35549
- } // Anything else is cell content.
35550
-
35551
- effects.enter('temporaryTableCellContent')
35552
- return inCellContentBody(code)
35553
- }
35554
- /** @type {State} */
35555
-
35556
- function inWhitespaceBody(code) {
35557
35880
  if (markdownSpace(code)) {
35558
- effects.consume(code)
35559
- return inWhitespaceBody
35881
+ return factorySpace(effects, bodyRowBreak, 'whitespace')(code)
35560
35882
  }
35561
35883
 
35562
- effects.exit('whitespace')
35563
- return cellBreakBody(code)
35884
+ // Anything else is cell content.
35885
+ effects.enter('data')
35886
+ return bodyRowData(code)
35564
35887
  }
35565
- /** @type {State} */
35566
35888
 
35567
- function inCellContentBody(code) {
35568
- // EOF, whitespace, pipe
35889
+ /**
35890
+ * In table body row data.
35891
+ *
35892
+ * ```markdown
35893
+ * | | a |
35894
+ * | | - |
35895
+ * > | | b |
35896
+ * ^
35897
+ * ```
35898
+ *
35899
+ * @type {State}
35900
+ */
35901
+ function bodyRowData(code) {
35569
35902
  if (code === null || code === 124 || markdownLineEndingOrSpace(code)) {
35570
- effects.exit('temporaryTableCellContent')
35571
- return cellBreakBody(code)
35903
+ effects.exit('data')
35904
+ return bodyRowBreak(code)
35572
35905
  }
35573
-
35574
35906
  effects.consume(code)
35575
- return code === 92 ? inCellContentEscapeBody : inCellContentBody
35907
+ return code === 92 ? bodyRowEscape : bodyRowData
35576
35908
  }
35577
- /** @type {State} */
35578
35909
 
35579
- function inCellContentEscapeBody(code) {
35910
+ /**
35911
+ * In table body row escape.
35912
+ *
35913
+ * ```markdown
35914
+ * | | a |
35915
+ * | | ---- |
35916
+ * > | | b\-c |
35917
+ * ^
35918
+ * ```
35919
+ *
35920
+ * @type {State}
35921
+ */
35922
+ function bodyRowEscape(code) {
35580
35923
  if (code === 92 || code === 124) {
35581
35924
  effects.consume(code)
35582
- return inCellContentBody
35583
- } // Anything else.
35584
-
35585
- return inCellContentBody(code)
35586
- }
35587
- /** @type {State} */
35588
-
35589
- function atRowEndBody(code) {
35590
- effects.exit('tableRow')
35591
-
35592
- if (code === null) {
35593
- return tableBodyClose(code)
35925
+ return bodyRowData
35594
35926
  }
35595
-
35596
- return effects.check(
35597
- nextPrefixedOrBlank,
35598
- tableBodyClose,
35599
- effects.attempt(
35600
- {
35601
- tokenize: tokenizeRowEnd,
35602
- partial: true
35603
- },
35604
- factorySpace(effects, rowStartBody, 'linePrefix', 4),
35605
- tableBodyClose
35606
- )
35607
- )(code)
35927
+ return bodyRowData(code)
35608
35928
  }
35609
- /** @type {State} */
35610
-
35611
- function tableBodyClose(code) {
35612
- effects.exit('tableBody')
35613
- return tableClose(code)
35614
- }
35615
- /** @type {Tokenizer} */
35929
+ }
35616
35930
 
35617
- function tokenizeRowEnd(effects, ok, nok) {
35618
- return start
35619
- /** @type {State} */
35931
+ /** @type {Resolver} */
35932
+ // eslint-disable-next-line complexity
35933
+ function resolveTable(events, context) {
35934
+ let index = -1
35935
+ let inFirstCellAwaitingPipe = true
35936
+ /** @type {RowKind} */
35937
+ let rowKind = 0
35938
+ /** @type {Range} */
35939
+ let lastCell = [0, 0, 0, 0]
35940
+ /** @type {Range} */
35941
+ let cell = [0, 0, 0, 0]
35942
+ let afterHeadAwaitingFirstBodyRow = false
35943
+ let lastTableEnd = 0
35944
+ /** @type {Token | undefined} */
35945
+ let currentTable
35946
+ /** @type {Token | undefined} */
35947
+ let currentBody
35948
+ /** @type {Token | undefined} */
35949
+ let currentCell
35950
+ const map = new EditMap()
35951
+ while (++index < events.length) {
35952
+ const event = events[index]
35953
+ const token = event[1]
35954
+ if (event[0] === 'enter') {
35955
+ // Start of head.
35956
+ if (token.type === 'tableHead') {
35957
+ afterHeadAwaitingFirstBodyRow = false
35620
35958
 
35621
- function start(code) {
35622
- effects.enter('lineEnding')
35623
- effects.consume(code)
35624
- effects.exit('lineEnding')
35625
- return factorySpace(effects, prefixed, 'linePrefix')
35626
- }
35627
- /** @type {State} */
35959
+ // Inject previous (body end and) table end.
35960
+ if (lastTableEnd !== 0) {
35961
+ flushTableEnd(map, context, lastTableEnd, currentTable, currentBody)
35962
+ currentBody = undefined
35963
+ lastTableEnd = 0
35964
+ }
35628
35965
 
35629
- function prefixed(code) {
35630
- // Blank or interrupting line.
35631
- if (
35632
- self.parser.lazy[self.now().line] ||
35633
- code === null ||
35634
- markdownLineEnding(code)
35966
+ // Inject table start.
35967
+ currentTable = {
35968
+ type: 'table',
35969
+ start: Object.assign({}, token.start),
35970
+ // Note: correct end is set later.
35971
+ end: Object.assign({}, token.end)
35972
+ }
35973
+ map.add(index, 0, [['enter', currentTable, context]])
35974
+ } else if (
35975
+ token.type === 'tableRow' ||
35976
+ token.type === 'tableDelimiterRow'
35635
35977
  ) {
35636
- return nok(code)
35978
+ inFirstCellAwaitingPipe = true
35979
+ currentCell = undefined
35980
+ lastCell = [0, 0, 0, 0]
35981
+ cell = [0, index + 1, 0, 0]
35982
+
35983
+ // Inject table body start.
35984
+ if (afterHeadAwaitingFirstBodyRow) {
35985
+ afterHeadAwaitingFirstBodyRow = false
35986
+ currentBody = {
35987
+ type: 'tableBody',
35988
+ start: Object.assign({}, token.start),
35989
+ // Note: correct end is set later.
35990
+ end: Object.assign({}, token.end)
35991
+ }
35992
+ map.add(index, 0, [['enter', currentBody, context]])
35993
+ }
35994
+ rowKind = token.type === 'tableDelimiterRow' ? 2 : currentBody ? 3 : 1
35637
35995
  }
35638
-
35639
- const tail = self.events[self.events.length - 1] // Indented code can interrupt delimiter and body rows.
35640
-
35641
- if (
35642
- !self.parser.constructs.disable.null.includes('codeIndented') &&
35643
- tail &&
35644
- tail[1].type === 'linePrefix' &&
35645
- tail[2].sliceSerialize(tail[1], true).length >= 4
35996
+ // Cell data.
35997
+ else if (
35998
+ rowKind &&
35999
+ (token.type === 'data' ||
36000
+ token.type === 'tableDelimiterMarker' ||
36001
+ token.type === 'tableDelimiterFiller')
35646
36002
  ) {
35647
- return nok(code)
36003
+ inFirstCellAwaitingPipe = false
36004
+
36005
+ // First value in cell.
36006
+ if (cell[2] === 0) {
36007
+ if (lastCell[1] !== 0) {
36008
+ cell[0] = cell[1]
36009
+ currentCell = flushCell(
36010
+ map,
36011
+ context,
36012
+ lastCell,
36013
+ rowKind,
36014
+ undefined,
36015
+ currentCell
36016
+ )
36017
+ lastCell = [0, 0, 0, 0]
36018
+ }
36019
+ cell[2] = index
36020
+ }
36021
+ } else if (token.type === 'tableCellDivider') {
36022
+ if (inFirstCellAwaitingPipe) {
36023
+ inFirstCellAwaitingPipe = false
36024
+ } else {
36025
+ if (lastCell[1] !== 0) {
36026
+ cell[0] = cell[1]
36027
+ currentCell = flushCell(
36028
+ map,
36029
+ context,
36030
+ lastCell,
36031
+ rowKind,
36032
+ undefined,
36033
+ currentCell
36034
+ )
36035
+ }
36036
+ lastCell = cell
36037
+ cell = [lastCell[1], index, 0, 0]
36038
+ }
36039
+ }
36040
+ }
36041
+ // Exit events.
36042
+ else if (token.type === 'tableHead') {
36043
+ afterHeadAwaitingFirstBodyRow = true
36044
+ lastTableEnd = index
36045
+ } else if (
36046
+ token.type === 'tableRow' ||
36047
+ token.type === 'tableDelimiterRow'
36048
+ ) {
36049
+ lastTableEnd = index
36050
+ if (lastCell[1] !== 0) {
36051
+ cell[0] = cell[1]
36052
+ currentCell = flushCell(
36053
+ map,
36054
+ context,
36055
+ lastCell,
36056
+ rowKind,
36057
+ index,
36058
+ currentCell
36059
+ )
36060
+ } else if (cell[1] !== 0) {
36061
+ currentCell = flushCell(map, context, cell, rowKind, index, currentCell)
35648
36062
  }
36063
+ rowKind = 0
36064
+ } else if (
36065
+ rowKind &&
36066
+ (token.type === 'data' ||
36067
+ token.type === 'tableDelimiterMarker' ||
36068
+ token.type === 'tableDelimiterFiller')
36069
+ ) {
36070
+ cell[3] = index
36071
+ }
36072
+ }
36073
+ if (lastTableEnd !== 0) {
36074
+ flushTableEnd(map, context, lastTableEnd, currentTable, currentBody)
36075
+ }
36076
+ map.consume(context.events)
35649
36077
 
35650
- self._gfmTableDynamicInterruptHack = true
35651
- return effects.check(
35652
- self.parser.constructs.flow,
35653
- function (code) {
35654
- self._gfmTableDynamicInterruptHack = false
35655
- return nok(code)
35656
- },
35657
- function (code) {
35658
- self._gfmTableDynamicInterruptHack = false
35659
- return ok(code)
35660
- }
35661
- )(code)
36078
+ // To do: move this into `html`, when events are exposed there.
36079
+ // That’s what `markdown-rs` does.
36080
+ // That needs updates to `mdast-util-gfm-table`.
36081
+ index = -1
36082
+ while (++index < context.events.length) {
36083
+ const event = context.events[index]
36084
+ if (event[0] === 'enter' && event[1].type === 'table') {
36085
+ // @ts-expect-error: custom field.
36086
+ event[1]._align = gfmTableAlign(context.events, index)
35662
36087
  }
35663
36088
  }
36089
+ return events
35664
36090
  }
35665
- /** @type {Tokenizer} */
35666
-
35667
- function tokenizeNextPrefixedOrBlank(effects, ok, nok) {
35668
- let size = 0
35669
- return start
35670
- /** @type {State} */
35671
36091
 
35672
- function start(code) {
35673
- // This is a check, so we don’t care about tokens, but we open a bogus one
35674
- // so we’re valid.
35675
- effects.enter('check') // EOL.
35676
-
35677
- effects.consume(code)
35678
- return whitespace
36092
+ /// Generate a cell.
36093
+ /**
36094
+ *
36095
+ * @param {EditMap} map
36096
+ * @param {TokenizeContext} context
36097
+ * @param {Range} range
36098
+ * @param {RowKind} rowKind
36099
+ * @param {number | undefined} rowEnd
36100
+ * @param {Token | undefined} previousCell
36101
+ * @returns {Token | undefined}
36102
+ */
36103
+ // eslint-disable-next-line max-params
36104
+ function flushCell(map, context, range, rowKind, rowEnd, previousCell) {
36105
+ // `markdown-rs` uses:
36106
+ // rowKind === 2 ? 'tableDelimiterCell' : 'tableCell'
36107
+ const groupName =
36108
+ rowKind === 1
36109
+ ? 'tableHeader'
36110
+ : rowKind === 2
36111
+ ? 'tableDelimiter'
36112
+ : 'tableData'
36113
+ // `markdown-rs` uses:
36114
+ // rowKind === 2 ? 'tableDelimiterCellValue' : 'tableCellText'
36115
+ const valueName = 'tableContent'
36116
+
36117
+ // Insert an exit for the previous cell, if there is one.
36118
+ //
36119
+ // ```markdown
36120
+ // > | | aa | bb | cc |
36121
+ // ^-- exit
36122
+ // ^^^^-- this cell
36123
+ // ```
36124
+ if (range[0] !== 0) {
36125
+ previousCell.end = Object.assign({}, getPoint(context.events, range[0]))
36126
+ map.add(range[0], 0, [['exit', previousCell, context]])
35679
36127
  }
35680
- /** @type {State} */
35681
36128
 
35682
- function whitespace(code) {
35683
- if (code === -1 || code === 32) {
35684
- effects.consume(code)
35685
- size++
35686
- return size === 4 ? ok : whitespace
35687
- } // EOF or whitespace
36129
+ // Insert enter of this cell.
36130
+ //
36131
+ // ```markdown
36132
+ // > | | aa | bb | cc |
36133
+ // ^-- enter
36134
+ // ^^^^-- this cell
36135
+ // ```
36136
+ const now = getPoint(context.events, range[1])
36137
+ previousCell = {
36138
+ type: groupName,
36139
+ start: Object.assign({}, now),
36140
+ // Note: correct end is set later.
36141
+ end: Object.assign({}, now)
36142
+ }
36143
+ map.add(range[1], 0, [['enter', previousCell, context]])
35688
36144
 
35689
- if (code === null || markdownLineEndingOrSpace(code)) {
35690
- return ok(code)
35691
- } // Anything else.
36145
+ // Insert text start at first data start and end at last data end, and
36146
+ // remove events between.
36147
+ //
36148
+ // ```markdown
36149
+ // > | | aa | bb | cc |
36150
+ // ^-- enter
36151
+ // ^-- exit
36152
+ // ^^^^-- this cell
36153
+ // ```
36154
+ if (range[2] !== 0) {
36155
+ const relatedStart = getPoint(context.events, range[2])
36156
+ const relatedEnd = getPoint(context.events, range[3])
36157
+ const valueToken = {
36158
+ type: valueName,
36159
+ start: Object.assign({}, relatedStart),
36160
+ end: Object.assign({}, relatedEnd)
36161
+ }
36162
+ map.add(range[2], 0, [['enter', valueToken, context]])
36163
+ if (rowKind !== 2) {
36164
+ // Fix positional info on remaining events
36165
+ const start = context.events[range[2]]
36166
+ const end = context.events[range[3]]
36167
+ start[1].end = Object.assign({}, end[1].end)
36168
+ start[1].type = 'chunkText'
36169
+ // @ts-expect-error It’s fine.
36170
+ start[1].contentType = 'text'
36171
+
36172
+ // Remove if needed.
36173
+ if (range[3] > range[2] + 1) {
36174
+ const a = range[2] + 1
36175
+ const b = range[3] - range[2] - 1
36176
+ map.add(a, b, [])
36177
+ }
36178
+ }
36179
+ map.add(range[3] + 1, 0, [['exit', valueToken, context]])
36180
+ }
36181
+
36182
+ // Insert an exit for the last cell, if at the row end.
36183
+ //
36184
+ // ```markdown
36185
+ // > | | aa | bb | cc |
36186
+ // ^-- exit
36187
+ // ^^^^^^-- this cell (the last one contains two “between” parts)
36188
+ // ```
36189
+ if (rowEnd !== undefined) {
36190
+ previousCell.end = Object.assign({}, getPoint(context.events, rowEnd))
36191
+ map.add(rowEnd, 0, [['exit', previousCell, context]])
36192
+ previousCell = undefined
36193
+ }
36194
+ return previousCell
36195
+ }
35692
36196
 
35693
- return nok(code)
36197
+ /**
36198
+ * Generate table end (and table body end).
36199
+ *
36200
+ * @param {EditMap} map
36201
+ * @param {TokenizeContext} context
36202
+ * @param {number} index
36203
+ * @param {Token} table
36204
+ * @param {Token | undefined} tableBody
36205
+ */
36206
+ // eslint-disable-next-line max-params
36207
+ function flushTableEnd(map, context, index, table, tableBody) {
36208
+ /** @type {Array<Event>} */
36209
+ const exits = []
36210
+ const related = getPoint(context.events, index)
36211
+ if (tableBody) {
36212
+ tableBody.end = Object.assign({}, related)
36213
+ exits.push(['exit', tableBody, context])
35694
36214
  }
36215
+ table.end = Object.assign({}, related)
36216
+ exits.push(['exit', table, context])
36217
+ map.add(index + 1, 0, exits)
36218
+ }
36219
+
36220
+ /**
36221
+ * @param {Array<Event>} events
36222
+ * @param {number} index
36223
+ * @returns {readonly Point}
36224
+ */
36225
+ function getPoint(events, index) {
36226
+ const event = events[index]
36227
+ const side = event[0] === 'enter' ? 'start' : 'end'
36228
+ return event[1][side]
35695
36229
  }
35696
36230
 
35697
36231
  ;// CONCATENATED MODULE: ../node_modules/micromark-extension-gfm-task-list-item/lib/syntax.js
@@ -35861,10 +36395,10 @@ function spaceThenNonSpace(effects, ok, nok) {
35861
36395
 
35862
36396
  ;// CONCATENATED MODULE: ../node_modules/micromark-extension-gfm/index.js
35863
36397
  /**
36398
+ * @typedef {import('micromark-extension-gfm-footnote').HtmlOptions} HtmlOptions
36399
+ * @typedef {import('micromark-extension-gfm-strikethrough').Options} Options
35864
36400
  * @typedef {import('micromark-util-types').Extension} Extension
35865
36401
  * @typedef {import('micromark-util-types').HtmlExtension} HtmlExtension
35866
- * @typedef {import('micromark-extension-gfm-strikethrough').Options} Options
35867
- * @typedef {import('micromark-extension-gfm-footnote').HtmlOptions} HtmlOptions
35868
36402
  */
35869
36403
 
35870
36404
 
@@ -35876,10 +36410,15 @@ function spaceThenNonSpace(effects, ok, nok) {
35876
36410
 
35877
36411
 
35878
36412
  /**
35879
- * Support GFM or markdown on github.com.
36413
+ * Create an extension for `micromark` to enable GFM syntax.
35880
36414
  *
35881
- * @param {Options} [options]
36415
+ * @param {Options | null | undefined} [options]
36416
+ * Configuration (optional).
36417
+ *
36418
+ * Passed to `micromark-extens-gfm-strikethrough`.
35882
36419
  * @returns {Extension}
36420
+ * Extension for `micromark` that can be passed in `extensions` to enable GFM
36421
+ * syntax.
35883
36422
  */
35884
36423
  function gfm(options) {
35885
36424
  return combineExtensions([
@@ -35892,10 +36431,15 @@ function gfm(options) {
35892
36431
  }
35893
36432
 
35894
36433
  /**
35895
- * Support to compile GFM to HTML.
36434
+ * Create an extension for `micromark` to support GFM when serializing to HTML.
36435
+ *
36436
+ * @param {HtmlOptions | null | undefined} [options]
36437
+ * Configuration.
35896
36438
  *
35897
- * @param {HtmlOptions} [options]
36439
+ * Passed to `micromark-extens-gfm-footnote`.
35898
36440
  * @returns {HtmlExtension}
36441
+ * Extension for `micromark` that can be passed in `htmlExtensions` to
36442
+ * support GFM when serializing to HTML.
35899
36443
  */
35900
36444
  function gfmHtml(options) {
35901
36445
  return combineHtmlExtensions([
@@ -73656,7 +74200,7 @@ var commands_getCommands=function getCommands(){return[bold,italic,strikeThrough
73656
74200
  */_createClass(TextAreaTextApi,[{key:"replaceSelection",value:function replaceSelection(text){insertTextAtPosition(this.textArea,text);return getStateFromTextArea(this.textArea);}/**
73657
74201
  * Selects the specified text range
73658
74202
  * @param selection
73659
- */},{key:"setSelectionRange",value:function setSelectionRange(selection){this.textArea.focus();this.textArea.selectionStart=selection.start;this.textArea.selectionEnd=selection.end;return getStateFromTextArea(this.textArea);}}]);return TextAreaTextApi;}();var TextAreaCommandOrchestrator=/*#__PURE__*/function(){function TextAreaCommandOrchestrator(textArea){_classCallCheck(this,TextAreaCommandOrchestrator);this.textArea=void 0;this.textApi=void 0;this.textArea=textArea;this.textApi=new TextAreaTextApi(textArea);}_createClass(TextAreaCommandOrchestrator,[{key:"getState",value:function getState(){if(!this.textArea)return false;return getStateFromTextArea(this.textArea);}},{key:"executeCommand",value:function executeCommand(command,dispatch,state,shortcuts){command.execute&&command.execute(_objectSpread2({command:command},getStateFromTextArea(this.textArea)),this.textApi,dispatch,state,shortcuts);}}]);return TextAreaCommandOrchestrator;}();
74203
+ */},{key:"setSelectionRange",value:function setSelectionRange(selection){this.textArea.focus();this.textArea.selectionStart=selection.start;this.textArea.selectionEnd=selection.end;return getStateFromTextArea(this.textArea);}}]);return TextAreaTextApi;}();var TextAreaCommandOrchestrator=/*#__PURE__*/function(){function TextAreaCommandOrchestrator(textArea){_classCallCheck(this,TextAreaCommandOrchestrator);this.textArea=void 0;this.textApi=void 0;this.textArea=textArea;this.textApi=new TextAreaTextApi(textArea);}_createClass(TextAreaCommandOrchestrator,[{key:"getState",value:function getState(){if(!this.textArea)return false;return getStateFromTextArea(this.textArea);}},{key:"executeCommand",value:function executeCommand(command,dispatch,state,shortcuts){console.log('state:',state);command.execute&&command.execute(_objectSpread2({command:command},getStateFromTextArea(this.textArea)),this.textApi,dispatch,state,shortcuts);}}]);return TextAreaCommandOrchestrator;}();
73660
74204
  ;// CONCATENATED MODULE: ./src/components/TextArea/handleKeyDown.tsx
73661
74205
  /**
73662
74206
  * - `13` - `Enter`
@@ -73670,8 +74214,8 @@ var commands_getCommands=function getCommands(){return[bold,italic,strikeThrough
73670
74214
  // extracted by mini-css-extract-plugin
73671
74215
  /* harmony default export */ const TextArea = ({});
73672
74216
  ;// CONCATENATED MODULE: ./src/components/TextArea/Textarea.tsx
73673
- var Textarea_excluded=["prefixCls","onChange"];function Textarea(props){var prefixCls=props.prefixCls,_onChange=props.onChange,other=_objectWithoutProperties(props,Textarea_excluded);var _useContext=(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useContext)(EditorContext),markdown=_useContext.markdown,commands=_useContext.commands,fullscreen=_useContext.fullscreen,preview=_useContext.preview,highlightEnable=_useContext.highlightEnable,extraCommands=_useContext.extraCommands,tabSize=_useContext.tabSize,defaultTabEnable=_useContext.defaultTabEnable,dispatch=_useContext.dispatch;var textRef=external_root_React_commonjs2_react_commonjs_react_amd_react_default().useRef(null);var executeRef=external_root_React_commonjs2_react_commonjs_react_amd_react_default().useRef();var statesRef=external_root_React_commonjs2_react_commonjs_react_amd_react_default().useRef({fullscreen:fullscreen,preview:preview});(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useEffect)(function(){statesRef.current={fullscreen:fullscreen,preview:preview,highlightEnable:highlightEnable};},[fullscreen,preview,highlightEnable]);(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useEffect)(function(){if(textRef.current&&dispatch){var commandOrchestrator=new TextAreaCommandOrchestrator(textRef.current);executeRef.current=commandOrchestrator;dispatch({textarea:textRef.current,commandOrchestrator:commandOrchestrator});}// eslint-disable-next-line react-hooks/exhaustive-deps
73674
- },[]);var onKeyDown=function onKeyDown(e){handleKeyDown(e,tabSize,defaultTabEnable);shortcutsHandle(e,[].concat(_toConsumableArray(commands||[]),_toConsumableArray(extraCommands||[])),executeRef.current,dispatch,statesRef.current);};(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useEffect)(function(){if(textRef.current){textRef.current.addEventListener('keydown',onKeyDown);}return function(){if(textRef.current){// eslint-disable-next-line react-hooks/exhaustive-deps
74217
+ var Textarea_excluded=["prefixCls","onChange"],_excluded2=["markdown","commands","fullscreen","preview","highlightEnable","extraCommands","tabSize","defaultTabEnable","dispatch"];function Textarea(props){var prefixCls=props.prefixCls,_onChange=props.onChange,other=_objectWithoutProperties(props,Textarea_excluded);var _useContext=(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useContext)(EditorContext),markdown=_useContext.markdown,commands=_useContext.commands,fullscreen=_useContext.fullscreen,preview=_useContext.preview,highlightEnable=_useContext.highlightEnable,extraCommands=_useContext.extraCommands,tabSize=_useContext.tabSize,defaultTabEnable=_useContext.defaultTabEnable,dispatch=_useContext.dispatch,otherStore=_objectWithoutProperties(_useContext,_excluded2);var textRef=external_root_React_commonjs2_react_commonjs_react_amd_react_default().useRef(null);var executeRef=external_root_React_commonjs2_react_commonjs_react_amd_react_default().useRef();var statesRef=external_root_React_commonjs2_react_commonjs_react_amd_react_default().useRef({fullscreen:fullscreen,preview:preview});(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useEffect)(function(){statesRef.current={fullscreen:fullscreen,preview:preview,highlightEnable:highlightEnable};},[fullscreen,preview,highlightEnable]);(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useEffect)(function(){if(textRef.current&&dispatch){var commandOrchestrator=new TextAreaCommandOrchestrator(textRef.current);executeRef.current=commandOrchestrator;dispatch({textarea:textRef.current,commandOrchestrator:commandOrchestrator});}// eslint-disable-next-line react-hooks/exhaustive-deps
74218
+ },[]);var onKeyDown=function onKeyDown(e){handleKeyDown(e,tabSize,defaultTabEnable);console.log('otherStore:',otherStore);shortcutsHandle(e,[].concat(_toConsumableArray(commands||[]),_toConsumableArray(extraCommands||[])),executeRef.current,dispatch,statesRef.current);};(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useEffect)(function(){if(textRef.current){textRef.current.addEventListener('keydown',onKeyDown);}return function(){if(textRef.current){// eslint-disable-next-line react-hooks/exhaustive-deps
73675
74219
  textRef.current.removeEventListener('keydown',onKeyDown);}};// eslint-disable-next-line react-hooks/exhaustive-deps
73676
74220
  },[]);return/*#__PURE__*/(0,jsx_runtime.jsx)("textarea",_objectSpread2(_objectSpread2({autoComplete:"off",autoCorrect:"off",autoCapitalize:"off",spellCheck:false},other),{},{ref:textRef,className:"".concat(prefixCls,"-text-input ").concat(other.className?other.className:''),value:markdown,onChange:function onChange(e){dispatch&&dispatch({markdown:e.target.value});_onChange&&_onChange(e);}}));}
73677
74221
  ;// CONCATENATED MODULE: ./src/components/TextArea/index.tsx
@@ -73691,7 +74235,7 @@ function Child_Child(props){var _ref=props||{},prefixCls=_ref.prefixCls,groupNam
73691
74235
  function ToolbarItems(props){var prefixCls=props.prefixCls,overflow=props.overflow;var _useContext=(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useContext)(EditorContext),fullscreen=_useContext.fullscreen,preview=_useContext.preview,_useContext$barPopup=_useContext.barPopup,barPopup=_useContext$barPopup===void 0?{}:_useContext$barPopup,components=_useContext.components,commandOrchestrator=_useContext.commandOrchestrator,dispatch=_useContext.dispatch;var originalOverflow=(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useRef)('');function handleClick(command,name){if(!dispatch)return;var state={barPopup:_objectSpread2({},barPopup)};if(command.keyCommand==='preview'){state.preview=command.value;}if(command.keyCommand==='fullscreen'){state.fullscreen=!fullscreen;}if(props.commands&&command.keyCommand==='group'){props.commands.forEach(function(item){if(name===item.groupName){state.barPopup[name]=true;}else if(item.keyCommand){state.barPopup[item.groupName]=false;}});}else if(name||command.parent){Object.keys(state.barPopup||{}).forEach(function(keyName){state.barPopup[keyName]=false;});}if(Object.keys(state).length){dispatch(_objectSpread2({},state));}commandOrchestrator&&commandOrchestrator.executeCommand(command);}(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useEffect)(function(){if(document&&overflow){if(fullscreen){// prevent scroll on fullscreen
73692
74236
  document.body.style.overflow='hidden';}else{// get the original overflow only the first time
73693
74237
  if(!originalOverflow.current){originalOverflow.current=window.getComputedStyle(document.body,null).overflow;}// reset to the original overflow
73694
- document.body.style.overflow=originalOverflow.current;}}},[fullscreen,originalOverflow,overflow]);return/*#__PURE__*/(0,jsx_runtime.jsx)("ul",{children:(props.commands||[]).map(function(item,idx){if(item.keyCommand==='divider'){return/*#__PURE__*/(0,jsx_runtime.jsx)("li",_objectSpread2(_objectSpread2({},item.liProps),{},{className:"".concat(prefixCls,"-toolbar-divider")}),idx);}if(!item.keyCommand)return/*#__PURE__*/(0,jsx_runtime.jsx)(external_root_React_commonjs2_react_commonjs_react_amd_react_.Fragment,{},idx);var activeBtn=fullscreen&&item.keyCommand==='fullscreen'||item.keyCommand==='preview'&&preview===item.value;var childNode=item.children&&typeof item.children==='function'?item.children({getState:function getState(){return commandOrchestrator.getState();},textApi:commandOrchestrator?commandOrchestrator.textApi:undefined,close:function close(){return handleClick({},item.groupName);},execute:function execute(){return handleClick({execute:item.execute});}}):undefined;var disabled=barPopup&&preview&&preview==='preview'&&!/(preview|fullscreen)/.test(item.keyCommand);var render=(components===null||components===void 0?void 0:components.toolbar)||item.render;var com=render&&typeof render==='function'?render(item,!!disabled,handleClick,idx):null;return/*#__PURE__*/(0,jsx_runtime.jsxs)("li",_objectSpread2(_objectSpread2({},item.liProps),{},{className:activeBtn?"active":'',children:[com&&/*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().isValidElement(com)&&com,!com&&!item.buttonProps&&item.icon,!com&&item.buttonProps&&/*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createElement('button',_objectSpread2(_objectSpread2({type:'button',key:idx,disabled:disabled,'data-name':item.name},item.buttonProps),{},{onClick:function onClick(evn){evn.stopPropagation();handleClick(item,item.groupName);}}),item.icon),item.children&&/*#__PURE__*/(0,jsx_runtime.jsx)(Child_Child,{overflow:overflow,groupName:item.groupName,prefixCls:prefixCls,children:childNode,commands:Array.isArray(item.children)?item.children:undefined})]}),idx);})});}function Toolbar_Toolbar(){var props=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};var prefixCls=props.prefixCls,toolbarBottom=props.toolbarBottom,isChild=props.isChild;var _useContext2=(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useContext)(EditorContext),commands=_useContext2.commands,extraCommands=_useContext2.extraCommands;var bottomClassName=toolbarBottom?'bottom':'';return/*#__PURE__*/(0,jsx_runtime.jsxs)("div",{className:"".concat(prefixCls,"-toolbar ").concat(bottomClassName),children:[/*#__PURE__*/(0,jsx_runtime.jsx)(ToolbarItems,_objectSpread2(_objectSpread2({},props),{},{commands:props.commands||commands||[]})),!isChild&&/*#__PURE__*/(0,jsx_runtime.jsx)(ToolbarItems,_objectSpread2(_objectSpread2({},props),{},{commands:extraCommands||[]}))]});}
74238
+ document.body.style.overflow=originalOverflow.current;}}},[fullscreen,originalOverflow,overflow]);return/*#__PURE__*/(0,jsx_runtime.jsx)("ul",{children:(props.commands||[]).map(function(item,idx){if(item.keyCommand==='divider'){return/*#__PURE__*/(0,jsx_runtime.jsx)("li",_objectSpread2(_objectSpread2({},item.liProps),{},{className:"".concat(prefixCls,"-toolbar-divider")}),idx);}if(!item.keyCommand)return/*#__PURE__*/(0,jsx_runtime.jsx)(external_root_React_commonjs2_react_commonjs_react_amd_react_.Fragment,{},idx);var activeBtn=fullscreen&&item.keyCommand==='fullscreen'||item.keyCommand==='preview'&&preview===item.value;var childNode=item.children&&typeof item.children==='function'?item.children({getState:function getState(){return commandOrchestrator.getState();},textApi:commandOrchestrator?commandOrchestrator.textApi:undefined,close:function close(){return handleClick({},item.groupName);},execute:function execute(){return handleClick({execute:item.execute});},dispatch:dispatch}):undefined;var disabled=barPopup&&preview&&preview==='preview'&&!/(preview|fullscreen)/.test(item.keyCommand);var render=(components===null||components===void 0?void 0:components.toolbar)||item.render;var com=render&&typeof render==='function'?render(item,!!disabled,handleClick,idx):null;return/*#__PURE__*/(0,jsx_runtime.jsxs)("li",_objectSpread2(_objectSpread2({},item.liProps),{},{className:activeBtn?"active":'',children:[com&&/*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().isValidElement(com)&&com,!com&&!item.buttonProps&&item.icon,!com&&item.buttonProps&&/*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createElement('button',_objectSpread2(_objectSpread2({type:'button',key:idx,disabled:disabled,'data-name':item.name},item.buttonProps),{},{onClick:function onClick(evn){evn.stopPropagation();handleClick(item,item.groupName);}}),item.icon),item.children&&/*#__PURE__*/(0,jsx_runtime.jsx)(Child_Child,{overflow:overflow,groupName:item.groupName,prefixCls:prefixCls,children:childNode,commands:Array.isArray(item.children)?item.children:undefined})]}),idx);})});}function Toolbar_Toolbar(){var props=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};var prefixCls=props.prefixCls,toolbarBottom=props.toolbarBottom,isChild=props.isChild;var _useContext2=(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useContext)(EditorContext),commands=_useContext2.commands,extraCommands=_useContext2.extraCommands;var bottomClassName=toolbarBottom?'bottom':'';return/*#__PURE__*/(0,jsx_runtime.jsxs)("div",{className:"".concat(prefixCls,"-toolbar ").concat(bottomClassName),children:[/*#__PURE__*/(0,jsx_runtime.jsx)(ToolbarItems,_objectSpread2(_objectSpread2({},props),{},{commands:props.commands||commands||[]})),!isChild&&/*#__PURE__*/(0,jsx_runtime.jsx)(ToolbarItems,_objectSpread2(_objectSpread2({},props),{},{commands:extraCommands||[]}))]});}
73695
74239
  ;// CONCATENATED MODULE: ./src/components/DragBar/index.less
73696
74240
  // extracted by mini-css-extract-plugin
73697
74241
  /* harmony default export */ const DragBar = ({});