mdwysiwyg 0.1.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/index.cjs ADDED
@@ -0,0 +1,3941 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ MarkdownEditor: () => MarkdownEditor
34
+ });
35
+ module.exports = __toCommonJS(index_exports);
36
+
37
+ // src/components/MarkdownEditor/MarkdownEditor.tsx
38
+ var import_react9 = require("react");
39
+ var import_react10 = require("@tiptap/react");
40
+ var import_core2 = require("@tiptap/core");
41
+
42
+ // src/components/MarkdownEditor/markdown/tiptapMarkdownBridge.ts
43
+ var import_core = require("@tiptap/core");
44
+ var import_starter_kit = __toESM(require("@tiptap/starter-kit"), 1);
45
+ var import_extension_table = __toESM(require("@tiptap/extension-table"), 1);
46
+ var import_extension_table_row = __toESM(require("@tiptap/extension-table-row"), 1);
47
+ var import_extension_table_cell = __toESM(require("@tiptap/extension-table-cell"), 1);
48
+ var import_extension_table_header = __toESM(require("@tiptap/extension-table-header"), 1);
49
+ var import_extension_task_list = __toESM(require("@tiptap/extension-task-list"), 1);
50
+ var import_extension_task_item = __toESM(require("@tiptap/extension-task-item"), 1);
51
+ var import_extension_link = __toESM(require("@tiptap/extension-link"), 1);
52
+ var import_extension_image = __toESM(require("@tiptap/extension-image"), 1);
53
+ var import_extension_code_block_lowlight = __toESM(require("@tiptap/extension-code-block-lowlight"), 1);
54
+ var import_lowlight = require("lowlight");
55
+
56
+ // node_modules/highlight.js/es/languages/json.js
57
+ var EXTENDED_NUMBER_RE = "([-+]?)(\\b0[xX][a-fA-F0-9]+|(\\b\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?)|NaN|[-+]?Infinity";
58
+ var EXTENDED_NUMBER_MODE = {
59
+ scope: "number",
60
+ match: EXTENDED_NUMBER_RE,
61
+ relevance: 0
62
+ };
63
+ function json(hljs) {
64
+ const ATTRIBUTE = {
65
+ className: "attr",
66
+ begin: /(("(\\.|[^\\"\r\n])*")|('(\\.|[^\\'\r\n])*'))(?=\s*:)/,
67
+ relevance: 1.01
68
+ };
69
+ const PUNCTUATION = {
70
+ match: /[{}[\],:]/,
71
+ className: "punctuation",
72
+ relevance: 0
73
+ };
74
+ const LITERALS3 = [
75
+ "true",
76
+ "false",
77
+ "null"
78
+ ];
79
+ const LITERALS_MODE = {
80
+ scope: "literal",
81
+ beginKeywords: LITERALS3.join(" ")
82
+ };
83
+ return {
84
+ name: "JSON",
85
+ aliases: ["jsonc", "json5"],
86
+ keywords: {
87
+ literal: LITERALS3
88
+ },
89
+ contains: [
90
+ ATTRIBUTE,
91
+ PUNCTUATION,
92
+ hljs.APOS_STRING_MODE,
93
+ hljs.QUOTE_STRING_MODE,
94
+ LITERALS_MODE,
95
+ EXTENDED_NUMBER_MODE,
96
+ hljs.C_LINE_COMMENT_MODE,
97
+ hljs.C_BLOCK_COMMENT_MODE
98
+ ],
99
+ illegal: "\\S"
100
+ };
101
+ }
102
+
103
+ // node_modules/highlight.js/es/languages/sql.js
104
+ function sql(hljs) {
105
+ const regex = hljs.regex;
106
+ const COMMENT_MODE = hljs.COMMENT("--", "$");
107
+ const STRING = {
108
+ scope: "string",
109
+ variants: [
110
+ {
111
+ begin: /'/,
112
+ end: /'/,
113
+ contains: [{ match: /''/ }]
114
+ }
115
+ ]
116
+ };
117
+ const QUOTED_IDENTIFIER = {
118
+ begin: /"/,
119
+ end: /"/,
120
+ contains: [{ match: /""/ }]
121
+ };
122
+ const LITERALS3 = [
123
+ "true",
124
+ "false",
125
+ // Not sure it's correct to call NULL literal, and clauses like IS [NOT] NULL look strange that way.
126
+ // "null",
127
+ "unknown"
128
+ ];
129
+ const MULTI_WORD_TYPES = [
130
+ "double precision",
131
+ "large object",
132
+ "with timezone",
133
+ "without timezone"
134
+ ];
135
+ const TYPES3 = [
136
+ "bigint",
137
+ "binary",
138
+ "blob",
139
+ "boolean",
140
+ "char",
141
+ "character",
142
+ "clob",
143
+ "date",
144
+ "dec",
145
+ "decfloat",
146
+ "decimal",
147
+ "float",
148
+ "int",
149
+ "integer",
150
+ "interval",
151
+ "nchar",
152
+ "nclob",
153
+ "national",
154
+ "numeric",
155
+ "real",
156
+ "row",
157
+ "smallint",
158
+ "time",
159
+ "timestamp",
160
+ "varchar",
161
+ "varying",
162
+ // modifier (character varying)
163
+ "varbinary"
164
+ ];
165
+ const NON_RESERVED_WORDS = [
166
+ "add",
167
+ "asc",
168
+ "collation",
169
+ "desc",
170
+ "final",
171
+ "first",
172
+ "last",
173
+ "view"
174
+ ];
175
+ const RESERVED_WORDS = [
176
+ "abs",
177
+ "acos",
178
+ "all",
179
+ "allocate",
180
+ "alter",
181
+ "and",
182
+ "any",
183
+ "are",
184
+ "array",
185
+ "array_agg",
186
+ "array_max_cardinality",
187
+ "as",
188
+ "asensitive",
189
+ "asin",
190
+ "asymmetric",
191
+ "at",
192
+ "atan",
193
+ "atomic",
194
+ "authorization",
195
+ "avg",
196
+ "begin",
197
+ "begin_frame",
198
+ "begin_partition",
199
+ "between",
200
+ "bigint",
201
+ "binary",
202
+ "blob",
203
+ "boolean",
204
+ "both",
205
+ "by",
206
+ "call",
207
+ "called",
208
+ "cardinality",
209
+ "cascaded",
210
+ "case",
211
+ "cast",
212
+ "ceil",
213
+ "ceiling",
214
+ "char",
215
+ "char_length",
216
+ "character",
217
+ "character_length",
218
+ "check",
219
+ "classifier",
220
+ "clob",
221
+ "close",
222
+ "coalesce",
223
+ "collate",
224
+ "collect",
225
+ "column",
226
+ "commit",
227
+ "condition",
228
+ "connect",
229
+ "constraint",
230
+ "contains",
231
+ "convert",
232
+ "copy",
233
+ "corr",
234
+ "corresponding",
235
+ "cos",
236
+ "cosh",
237
+ "count",
238
+ "covar_pop",
239
+ "covar_samp",
240
+ "create",
241
+ "cross",
242
+ "cube",
243
+ "cume_dist",
244
+ "current",
245
+ "current_catalog",
246
+ "current_date",
247
+ "current_default_transform_group",
248
+ "current_path",
249
+ "current_role",
250
+ "current_row",
251
+ "current_schema",
252
+ "current_time",
253
+ "current_timestamp",
254
+ "current_path",
255
+ "current_role",
256
+ "current_transform_group_for_type",
257
+ "current_user",
258
+ "cursor",
259
+ "cycle",
260
+ "date",
261
+ "day",
262
+ "deallocate",
263
+ "dec",
264
+ "decimal",
265
+ "decfloat",
266
+ "declare",
267
+ "default",
268
+ "define",
269
+ "delete",
270
+ "dense_rank",
271
+ "deref",
272
+ "describe",
273
+ "deterministic",
274
+ "disconnect",
275
+ "distinct",
276
+ "double",
277
+ "drop",
278
+ "dynamic",
279
+ "each",
280
+ "element",
281
+ "else",
282
+ "empty",
283
+ "end",
284
+ "end_frame",
285
+ "end_partition",
286
+ "end-exec",
287
+ "equals",
288
+ "escape",
289
+ "every",
290
+ "except",
291
+ "exec",
292
+ "execute",
293
+ "exists",
294
+ "exp",
295
+ "external",
296
+ "extract",
297
+ "false",
298
+ "fetch",
299
+ "filter",
300
+ "first_value",
301
+ "float",
302
+ "floor",
303
+ "for",
304
+ "foreign",
305
+ "frame_row",
306
+ "free",
307
+ "from",
308
+ "full",
309
+ "function",
310
+ "fusion",
311
+ "get",
312
+ "global",
313
+ "grant",
314
+ "group",
315
+ "grouping",
316
+ "groups",
317
+ "having",
318
+ "hold",
319
+ "hour",
320
+ "identity",
321
+ "in",
322
+ "indicator",
323
+ "initial",
324
+ "inner",
325
+ "inout",
326
+ "insensitive",
327
+ "insert",
328
+ "int",
329
+ "integer",
330
+ "intersect",
331
+ "intersection",
332
+ "interval",
333
+ "into",
334
+ "is",
335
+ "join",
336
+ "json_array",
337
+ "json_arrayagg",
338
+ "json_exists",
339
+ "json_object",
340
+ "json_objectagg",
341
+ "json_query",
342
+ "json_table",
343
+ "json_table_primitive",
344
+ "json_value",
345
+ "lag",
346
+ "language",
347
+ "large",
348
+ "last_value",
349
+ "lateral",
350
+ "lead",
351
+ "leading",
352
+ "left",
353
+ "like",
354
+ "like_regex",
355
+ "listagg",
356
+ "ln",
357
+ "local",
358
+ "localtime",
359
+ "localtimestamp",
360
+ "log",
361
+ "log10",
362
+ "lower",
363
+ "match",
364
+ "match_number",
365
+ "match_recognize",
366
+ "matches",
367
+ "max",
368
+ "member",
369
+ "merge",
370
+ "method",
371
+ "min",
372
+ "minute",
373
+ "mod",
374
+ "modifies",
375
+ "module",
376
+ "month",
377
+ "multiset",
378
+ "national",
379
+ "natural",
380
+ "nchar",
381
+ "nclob",
382
+ "new",
383
+ "no",
384
+ "none",
385
+ "normalize",
386
+ "not",
387
+ "nth_value",
388
+ "ntile",
389
+ "null",
390
+ "nullif",
391
+ "numeric",
392
+ "octet_length",
393
+ "occurrences_regex",
394
+ "of",
395
+ "offset",
396
+ "old",
397
+ "omit",
398
+ "on",
399
+ "one",
400
+ "only",
401
+ "open",
402
+ "or",
403
+ "order",
404
+ "out",
405
+ "outer",
406
+ "over",
407
+ "overlaps",
408
+ "overlay",
409
+ "parameter",
410
+ "partition",
411
+ "pattern",
412
+ "per",
413
+ "percent",
414
+ "percent_rank",
415
+ "percentile_cont",
416
+ "percentile_disc",
417
+ "period",
418
+ "portion",
419
+ "position",
420
+ "position_regex",
421
+ "power",
422
+ "precedes",
423
+ "precision",
424
+ "prepare",
425
+ "primary",
426
+ "procedure",
427
+ "ptf",
428
+ "range",
429
+ "rank",
430
+ "reads",
431
+ "real",
432
+ "recursive",
433
+ "ref",
434
+ "references",
435
+ "referencing",
436
+ "regr_avgx",
437
+ "regr_avgy",
438
+ "regr_count",
439
+ "regr_intercept",
440
+ "regr_r2",
441
+ "regr_slope",
442
+ "regr_sxx",
443
+ "regr_sxy",
444
+ "regr_syy",
445
+ "release",
446
+ "result",
447
+ "return",
448
+ "returns",
449
+ "revoke",
450
+ "right",
451
+ "rollback",
452
+ "rollup",
453
+ "row",
454
+ "row_number",
455
+ "rows",
456
+ "running",
457
+ "savepoint",
458
+ "scope",
459
+ "scroll",
460
+ "search",
461
+ "second",
462
+ "seek",
463
+ "select",
464
+ "sensitive",
465
+ "session_user",
466
+ "set",
467
+ "show",
468
+ "similar",
469
+ "sin",
470
+ "sinh",
471
+ "skip",
472
+ "smallint",
473
+ "some",
474
+ "specific",
475
+ "specifictype",
476
+ "sql",
477
+ "sqlexception",
478
+ "sqlstate",
479
+ "sqlwarning",
480
+ "sqrt",
481
+ "start",
482
+ "static",
483
+ "stddev_pop",
484
+ "stddev_samp",
485
+ "submultiset",
486
+ "subset",
487
+ "substring",
488
+ "substring_regex",
489
+ "succeeds",
490
+ "sum",
491
+ "symmetric",
492
+ "system",
493
+ "system_time",
494
+ "system_user",
495
+ "table",
496
+ "tablesample",
497
+ "tan",
498
+ "tanh",
499
+ "then",
500
+ "time",
501
+ "timestamp",
502
+ "timezone_hour",
503
+ "timezone_minute",
504
+ "to",
505
+ "trailing",
506
+ "translate",
507
+ "translate_regex",
508
+ "translation",
509
+ "treat",
510
+ "trigger",
511
+ "trim",
512
+ "trim_array",
513
+ "true",
514
+ "truncate",
515
+ "uescape",
516
+ "union",
517
+ "unique",
518
+ "unknown",
519
+ "unnest",
520
+ "update",
521
+ "upper",
522
+ "user",
523
+ "using",
524
+ "value",
525
+ "values",
526
+ "value_of",
527
+ "var_pop",
528
+ "var_samp",
529
+ "varbinary",
530
+ "varchar",
531
+ "varying",
532
+ "versioning",
533
+ "when",
534
+ "whenever",
535
+ "where",
536
+ "width_bucket",
537
+ "window",
538
+ "with",
539
+ "within",
540
+ "without",
541
+ "year"
542
+ ];
543
+ const RESERVED_FUNCTIONS = [
544
+ "abs",
545
+ "acos",
546
+ "array_agg",
547
+ "asin",
548
+ "atan",
549
+ "avg",
550
+ "cast",
551
+ "ceil",
552
+ "ceiling",
553
+ "coalesce",
554
+ "corr",
555
+ "cos",
556
+ "cosh",
557
+ "count",
558
+ "covar_pop",
559
+ "covar_samp",
560
+ "cume_dist",
561
+ "dense_rank",
562
+ "deref",
563
+ "element",
564
+ "exp",
565
+ "extract",
566
+ "first_value",
567
+ "floor",
568
+ "json_array",
569
+ "json_arrayagg",
570
+ "json_exists",
571
+ "json_object",
572
+ "json_objectagg",
573
+ "json_query",
574
+ "json_table",
575
+ "json_table_primitive",
576
+ "json_value",
577
+ "lag",
578
+ "last_value",
579
+ "lead",
580
+ "listagg",
581
+ "ln",
582
+ "log",
583
+ "log10",
584
+ "lower",
585
+ "max",
586
+ "min",
587
+ "mod",
588
+ "nth_value",
589
+ "ntile",
590
+ "nullif",
591
+ "percent_rank",
592
+ "percentile_cont",
593
+ "percentile_disc",
594
+ "position",
595
+ "position_regex",
596
+ "power",
597
+ "rank",
598
+ "regr_avgx",
599
+ "regr_avgy",
600
+ "regr_count",
601
+ "regr_intercept",
602
+ "regr_r2",
603
+ "regr_slope",
604
+ "regr_sxx",
605
+ "regr_sxy",
606
+ "regr_syy",
607
+ "row_number",
608
+ "sin",
609
+ "sinh",
610
+ "sqrt",
611
+ "stddev_pop",
612
+ "stddev_samp",
613
+ "substring",
614
+ "substring_regex",
615
+ "sum",
616
+ "tan",
617
+ "tanh",
618
+ "translate",
619
+ "translate_regex",
620
+ "treat",
621
+ "trim",
622
+ "trim_array",
623
+ "unnest",
624
+ "upper",
625
+ "value_of",
626
+ "var_pop",
627
+ "var_samp",
628
+ "width_bucket"
629
+ ];
630
+ const POSSIBLE_WITHOUT_PARENS = [
631
+ "current_catalog",
632
+ "current_date",
633
+ "current_default_transform_group",
634
+ "current_path",
635
+ "current_role",
636
+ "current_schema",
637
+ "current_transform_group_for_type",
638
+ "current_user",
639
+ "session_user",
640
+ "system_time",
641
+ "system_user",
642
+ "current_time",
643
+ "localtime",
644
+ "current_timestamp",
645
+ "localtimestamp"
646
+ ];
647
+ const COMBOS = [
648
+ "create table",
649
+ "insert into",
650
+ "primary key",
651
+ "foreign key",
652
+ "not null",
653
+ "alter table",
654
+ "add constraint",
655
+ "grouping sets",
656
+ "on overflow",
657
+ "character set",
658
+ "respect nulls",
659
+ "ignore nulls",
660
+ "nulls first",
661
+ "nulls last",
662
+ "depth first",
663
+ "breadth first"
664
+ ];
665
+ const FUNCTIONS = RESERVED_FUNCTIONS;
666
+ const KEYWORDS3 = [
667
+ ...RESERVED_WORDS,
668
+ ...NON_RESERVED_WORDS
669
+ ].filter((keyword) => {
670
+ return !RESERVED_FUNCTIONS.includes(keyword);
671
+ });
672
+ const VARIABLE = {
673
+ scope: "variable",
674
+ match: /@[a-z0-9][a-z0-9_]*/
675
+ };
676
+ const OPERATOR = {
677
+ scope: "operator",
678
+ match: /[-+*/=%^~]|&&?|\|\|?|!=?|<(?:=>?|<|>)?|>[>=]?/,
679
+ relevance: 0
680
+ };
681
+ const FUNCTION_CALL = {
682
+ match: regex.concat(/\b/, regex.either(...FUNCTIONS), /\s*\(/),
683
+ relevance: 0,
684
+ keywords: { built_in: FUNCTIONS }
685
+ };
686
+ function kws_to_regex(list) {
687
+ return regex.concat(
688
+ /\b/,
689
+ regex.either(...list.map((kw) => {
690
+ return kw.replace(/\s+/, "\\s+");
691
+ })),
692
+ /\b/
693
+ );
694
+ }
695
+ const MULTI_WORD_KEYWORDS = {
696
+ scope: "keyword",
697
+ match: kws_to_regex(COMBOS),
698
+ relevance: 0
699
+ };
700
+ function reduceRelevancy(list, {
701
+ exceptions,
702
+ when
703
+ } = {}) {
704
+ const qualifyFn = when;
705
+ exceptions = exceptions || [];
706
+ return list.map((item) => {
707
+ if (item.match(/\|\d+$/) || exceptions.includes(item)) {
708
+ return item;
709
+ } else if (qualifyFn(item)) {
710
+ return `${item}|0`;
711
+ } else {
712
+ return item;
713
+ }
714
+ });
715
+ }
716
+ return {
717
+ name: "SQL",
718
+ case_insensitive: true,
719
+ // does not include {} or HTML tags `</`
720
+ illegal: /[{}]|<\//,
721
+ keywords: {
722
+ $pattern: /\b[\w\.]+/,
723
+ keyword: reduceRelevancy(KEYWORDS3, { when: (x) => x.length < 3 }),
724
+ literal: LITERALS3,
725
+ type: TYPES3,
726
+ built_in: POSSIBLE_WITHOUT_PARENS
727
+ },
728
+ contains: [
729
+ {
730
+ scope: "type",
731
+ match: kws_to_regex(MULTI_WORD_TYPES)
732
+ },
733
+ MULTI_WORD_KEYWORDS,
734
+ FUNCTION_CALL,
735
+ VARIABLE,
736
+ STRING,
737
+ QUOTED_IDENTIFIER,
738
+ hljs.C_NUMBER_MODE,
739
+ hljs.C_BLOCK_COMMENT_MODE,
740
+ COMMENT_MODE,
741
+ OPERATOR
742
+ ]
743
+ };
744
+ }
745
+
746
+ // node_modules/highlight.js/es/languages/typescript.js
747
+ var IDENT_RE = "[A-Za-z$_][0-9A-Za-z$_]*";
748
+ var KEYWORDS = [
749
+ "as",
750
+ // for exports
751
+ "in",
752
+ "of",
753
+ "if",
754
+ "for",
755
+ "while",
756
+ "finally",
757
+ "var",
758
+ "new",
759
+ "function",
760
+ "do",
761
+ "return",
762
+ "void",
763
+ "else",
764
+ "break",
765
+ "catch",
766
+ "instanceof",
767
+ "with",
768
+ "throw",
769
+ "case",
770
+ "default",
771
+ "try",
772
+ "switch",
773
+ "continue",
774
+ "typeof",
775
+ "delete",
776
+ "let",
777
+ "yield",
778
+ "const",
779
+ "class",
780
+ // JS handles these with a special rule
781
+ // "get",
782
+ // "set",
783
+ "debugger",
784
+ "async",
785
+ "await",
786
+ "static",
787
+ "import",
788
+ "from",
789
+ "export",
790
+ "extends",
791
+ // It's reached stage 3, which is "recommended for implementation":
792
+ "using"
793
+ ];
794
+ var LITERALS = [
795
+ "true",
796
+ "false",
797
+ "null",
798
+ "undefined",
799
+ "NaN",
800
+ "Infinity"
801
+ ];
802
+ var TYPES = [
803
+ // Fundamental objects
804
+ "Object",
805
+ "Function",
806
+ "Boolean",
807
+ "Symbol",
808
+ // numbers and dates
809
+ "Math",
810
+ "Date",
811
+ "Number",
812
+ "BigInt",
813
+ // text
814
+ "String",
815
+ "RegExp",
816
+ // Indexed collections
817
+ "Array",
818
+ "Float32Array",
819
+ "Float64Array",
820
+ "Int8Array",
821
+ "Uint8Array",
822
+ "Uint8ClampedArray",
823
+ "Int16Array",
824
+ "Int32Array",
825
+ "Uint16Array",
826
+ "Uint32Array",
827
+ "BigInt64Array",
828
+ "BigUint64Array",
829
+ // Keyed collections
830
+ "Set",
831
+ "Map",
832
+ "WeakSet",
833
+ "WeakMap",
834
+ // Structured data
835
+ "ArrayBuffer",
836
+ "SharedArrayBuffer",
837
+ "Atomics",
838
+ "DataView",
839
+ "JSON",
840
+ // Control abstraction objects
841
+ "Promise",
842
+ "Generator",
843
+ "GeneratorFunction",
844
+ "AsyncFunction",
845
+ // Reflection
846
+ "Reflect",
847
+ "Proxy",
848
+ // Internationalization
849
+ "Intl",
850
+ // WebAssembly
851
+ "WebAssembly"
852
+ ];
853
+ var ERROR_TYPES = [
854
+ "Error",
855
+ "EvalError",
856
+ "InternalError",
857
+ "RangeError",
858
+ "ReferenceError",
859
+ "SyntaxError",
860
+ "TypeError",
861
+ "URIError"
862
+ ];
863
+ var BUILT_IN_GLOBALS = [
864
+ "setInterval",
865
+ "setTimeout",
866
+ "clearInterval",
867
+ "clearTimeout",
868
+ "require",
869
+ "exports",
870
+ "eval",
871
+ "isFinite",
872
+ "isNaN",
873
+ "parseFloat",
874
+ "parseInt",
875
+ "decodeURI",
876
+ "decodeURIComponent",
877
+ "encodeURI",
878
+ "encodeURIComponent",
879
+ "escape",
880
+ "unescape"
881
+ ];
882
+ var BUILT_IN_VARIABLES = [
883
+ "arguments",
884
+ "this",
885
+ "super",
886
+ "console",
887
+ "window",
888
+ "document",
889
+ "localStorage",
890
+ "sessionStorage",
891
+ "module",
892
+ "self",
893
+ "global"
894
+ // Node.js
895
+ ];
896
+ var BUILT_INS = [].concat(
897
+ BUILT_IN_GLOBALS,
898
+ TYPES,
899
+ ERROR_TYPES
900
+ );
901
+ function javascript(hljs) {
902
+ const regex = hljs.regex;
903
+ const hasClosingTag = (match, { after }) => {
904
+ const tag = "</" + match[0].slice(1);
905
+ const pos = match.input.indexOf(tag, after);
906
+ return pos !== -1;
907
+ };
908
+ const IDENT_RE$1 = IDENT_RE;
909
+ const FRAGMENT = {
910
+ begin: "<>",
911
+ end: "</>"
912
+ };
913
+ const XML_SELF_CLOSING = /<[A-Za-z0-9\\._:-]+\s*\/>/;
914
+ const XML_TAG = {
915
+ begin: /<[A-Za-z0-9\\._:-]+/,
916
+ end: /\/[A-Za-z0-9\\._:-]+>|\/>/,
917
+ /**
918
+ * @param {RegExpMatchArray} match
919
+ * @param {CallbackResponse} response
920
+ */
921
+ isTrulyOpeningTag: (match, response) => {
922
+ const afterMatchIndex = match[0].length + match.index;
923
+ const nextChar = match.input[afterMatchIndex];
924
+ if (
925
+ // HTML should not include another raw `<` inside a tag
926
+ // nested type?
927
+ // `<Array<Array<number>>`, etc.
928
+ nextChar === "<" || // the , gives away that this is not HTML
929
+ // `<T, A extends keyof T, V>`
930
+ nextChar === ","
931
+ ) {
932
+ response.ignoreMatch();
933
+ return;
934
+ }
935
+ if (nextChar === ">") {
936
+ if (!hasClosingTag(match, { after: afterMatchIndex })) {
937
+ response.ignoreMatch();
938
+ }
939
+ }
940
+ let m;
941
+ const afterMatch = match.input.substring(afterMatchIndex);
942
+ if (m = afterMatch.match(/^\s*=/)) {
943
+ response.ignoreMatch();
944
+ return;
945
+ }
946
+ if (m = afterMatch.match(/^\s+extends\s+/)) {
947
+ if (m.index === 0) {
948
+ response.ignoreMatch();
949
+ return;
950
+ }
951
+ }
952
+ }
953
+ };
954
+ const KEYWORDS$1 = {
955
+ $pattern: IDENT_RE,
956
+ keyword: KEYWORDS,
957
+ literal: LITERALS,
958
+ built_in: BUILT_INS,
959
+ "variable.language": BUILT_IN_VARIABLES
960
+ };
961
+ const decimalDigits2 = "[0-9](_?[0-9])*";
962
+ const frac2 = `\\.(${decimalDigits2})`;
963
+ const decimalInteger = `0|[1-9](_?[0-9])*|0[0-7]*[89][0-9]*`;
964
+ const NUMBER = {
965
+ className: "number",
966
+ variants: [
967
+ // DecimalLiteral
968
+ { begin: `(\\b(${decimalInteger})((${frac2})|\\.)?|(${frac2}))[eE][+-]?(${decimalDigits2})\\b` },
969
+ { begin: `\\b(${decimalInteger})\\b((${frac2})\\b|\\.)?|(${frac2})\\b` },
970
+ // DecimalBigIntegerLiteral
971
+ { begin: `\\b(0|[1-9](_?[0-9])*)n\\b` },
972
+ // NonDecimalIntegerLiteral
973
+ { begin: "\\b0[xX][0-9a-fA-F](_?[0-9a-fA-F])*n?\\b" },
974
+ { begin: "\\b0[bB][0-1](_?[0-1])*n?\\b" },
975
+ { begin: "\\b0[oO][0-7](_?[0-7])*n?\\b" },
976
+ // LegacyOctalIntegerLiteral (does not include underscore separators)
977
+ // https://tc39.es/ecma262/#sec-additional-syntax-numeric-literals
978
+ { begin: "\\b0[0-7]+n?\\b" }
979
+ ],
980
+ relevance: 0
981
+ };
982
+ const SUBST = {
983
+ className: "subst",
984
+ begin: "\\$\\{",
985
+ end: "\\}",
986
+ keywords: KEYWORDS$1,
987
+ contains: []
988
+ // defined later
989
+ };
990
+ const HTML_TEMPLATE = {
991
+ begin: ".?html`",
992
+ end: "",
993
+ starts: {
994
+ end: "`",
995
+ returnEnd: false,
996
+ contains: [
997
+ hljs.BACKSLASH_ESCAPE,
998
+ SUBST
999
+ ],
1000
+ subLanguage: "xml"
1001
+ }
1002
+ };
1003
+ const CSS_TEMPLATE = {
1004
+ begin: ".?css`",
1005
+ end: "",
1006
+ starts: {
1007
+ end: "`",
1008
+ returnEnd: false,
1009
+ contains: [
1010
+ hljs.BACKSLASH_ESCAPE,
1011
+ SUBST
1012
+ ],
1013
+ subLanguage: "css"
1014
+ }
1015
+ };
1016
+ const GRAPHQL_TEMPLATE = {
1017
+ begin: ".?gql`",
1018
+ end: "",
1019
+ starts: {
1020
+ end: "`",
1021
+ returnEnd: false,
1022
+ contains: [
1023
+ hljs.BACKSLASH_ESCAPE,
1024
+ SUBST
1025
+ ],
1026
+ subLanguage: "graphql"
1027
+ }
1028
+ };
1029
+ const TEMPLATE_STRING = {
1030
+ className: "string",
1031
+ begin: "`",
1032
+ end: "`",
1033
+ contains: [
1034
+ hljs.BACKSLASH_ESCAPE,
1035
+ SUBST
1036
+ ]
1037
+ };
1038
+ const JSDOC_COMMENT = hljs.COMMENT(
1039
+ /\/\*\*(?!\/)/,
1040
+ "\\*/",
1041
+ {
1042
+ relevance: 0,
1043
+ contains: [
1044
+ {
1045
+ begin: "(?=@[A-Za-z]+)",
1046
+ relevance: 0,
1047
+ contains: [
1048
+ {
1049
+ className: "doctag",
1050
+ begin: "@[A-Za-z]+"
1051
+ },
1052
+ {
1053
+ className: "type",
1054
+ begin: "\\{",
1055
+ end: "\\}",
1056
+ excludeEnd: true,
1057
+ excludeBegin: true,
1058
+ relevance: 0
1059
+ },
1060
+ {
1061
+ className: "variable",
1062
+ begin: IDENT_RE$1 + "(?=\\s*(-)|$)",
1063
+ endsParent: true,
1064
+ relevance: 0
1065
+ },
1066
+ // eat spaces (not newlines) so we can find
1067
+ // types or variables
1068
+ {
1069
+ begin: /(?=[^\n])\s/,
1070
+ relevance: 0
1071
+ }
1072
+ ]
1073
+ }
1074
+ ]
1075
+ }
1076
+ );
1077
+ const COMMENT = {
1078
+ className: "comment",
1079
+ variants: [
1080
+ JSDOC_COMMENT,
1081
+ hljs.C_BLOCK_COMMENT_MODE,
1082
+ hljs.C_LINE_COMMENT_MODE
1083
+ ]
1084
+ };
1085
+ const SUBST_INTERNALS = [
1086
+ hljs.APOS_STRING_MODE,
1087
+ hljs.QUOTE_STRING_MODE,
1088
+ HTML_TEMPLATE,
1089
+ CSS_TEMPLATE,
1090
+ GRAPHQL_TEMPLATE,
1091
+ TEMPLATE_STRING,
1092
+ // Skip numbers when they are part of a variable name
1093
+ { match: /\$\d+/ },
1094
+ NUMBER
1095
+ // This is intentional:
1096
+ // See https://github.com/highlightjs/highlight.js/issues/3288
1097
+ // hljs.REGEXP_MODE
1098
+ ];
1099
+ SUBST.contains = SUBST_INTERNALS.concat({
1100
+ // we need to pair up {} inside our subst to prevent
1101
+ // it from ending too early by matching another }
1102
+ begin: /\{/,
1103
+ end: /\}/,
1104
+ keywords: KEYWORDS$1,
1105
+ contains: [
1106
+ "self"
1107
+ ].concat(SUBST_INTERNALS)
1108
+ });
1109
+ const SUBST_AND_COMMENTS = [].concat(COMMENT, SUBST.contains);
1110
+ const PARAMS_CONTAINS = SUBST_AND_COMMENTS.concat([
1111
+ // eat recursive parens in sub expressions
1112
+ {
1113
+ begin: /(\s*)\(/,
1114
+ end: /\)/,
1115
+ keywords: KEYWORDS$1,
1116
+ contains: ["self"].concat(SUBST_AND_COMMENTS)
1117
+ }
1118
+ ]);
1119
+ const PARAMS = {
1120
+ className: "params",
1121
+ // convert this to negative lookbehind in v12
1122
+ begin: /(\s*)\(/,
1123
+ // to match the parms with
1124
+ end: /\)/,
1125
+ excludeBegin: true,
1126
+ excludeEnd: true,
1127
+ keywords: KEYWORDS$1,
1128
+ contains: PARAMS_CONTAINS
1129
+ };
1130
+ const CLASS_OR_EXTENDS = {
1131
+ variants: [
1132
+ // class Car extends vehicle
1133
+ {
1134
+ match: [
1135
+ /class/,
1136
+ /\s+/,
1137
+ IDENT_RE$1,
1138
+ /\s+/,
1139
+ /extends/,
1140
+ /\s+/,
1141
+ regex.concat(IDENT_RE$1, "(", regex.concat(/\./, IDENT_RE$1), ")*")
1142
+ ],
1143
+ scope: {
1144
+ 1: "keyword",
1145
+ 3: "title.class",
1146
+ 5: "keyword",
1147
+ 7: "title.class.inherited"
1148
+ }
1149
+ },
1150
+ // class Car
1151
+ {
1152
+ match: [
1153
+ /class/,
1154
+ /\s+/,
1155
+ IDENT_RE$1
1156
+ ],
1157
+ scope: {
1158
+ 1: "keyword",
1159
+ 3: "title.class"
1160
+ }
1161
+ }
1162
+ ]
1163
+ };
1164
+ const CLASS_REFERENCE = {
1165
+ relevance: 0,
1166
+ match: regex.either(
1167
+ // Hard coded exceptions
1168
+ /\bJSON/,
1169
+ // Float32Array, OutT
1170
+ /\b[A-Z][a-z]+([A-Z][a-z]*|\d)*/,
1171
+ // CSSFactory, CSSFactoryT
1172
+ /\b[A-Z]{2,}([A-Z][a-z]+|\d)+([A-Z][a-z]*)*/,
1173
+ // FPs, FPsT
1174
+ /\b[A-Z]{2,}[a-z]+([A-Z][a-z]+|\d)*([A-Z][a-z]*)*/
1175
+ // P
1176
+ // single letters are not highlighted
1177
+ // BLAH
1178
+ // this will be flagged as a UPPER_CASE_CONSTANT instead
1179
+ ),
1180
+ className: "title.class",
1181
+ keywords: {
1182
+ _: [
1183
+ // se we still get relevance credit for JS library classes
1184
+ ...TYPES,
1185
+ ...ERROR_TYPES
1186
+ ]
1187
+ }
1188
+ };
1189
+ const USE_STRICT = {
1190
+ label: "use_strict",
1191
+ className: "meta",
1192
+ relevance: 10,
1193
+ begin: /^\s*['"]use (strict|asm)['"]/
1194
+ };
1195
+ const FUNCTION_DEFINITION = {
1196
+ variants: [
1197
+ {
1198
+ match: [
1199
+ /function/,
1200
+ /\s+/,
1201
+ IDENT_RE$1,
1202
+ /(?=\s*\()/
1203
+ ]
1204
+ },
1205
+ // anonymous function
1206
+ {
1207
+ match: [
1208
+ /function/,
1209
+ /\s*(?=\()/
1210
+ ]
1211
+ }
1212
+ ],
1213
+ className: {
1214
+ 1: "keyword",
1215
+ 3: "title.function"
1216
+ },
1217
+ label: "func.def",
1218
+ contains: [PARAMS],
1219
+ illegal: /%/
1220
+ };
1221
+ const UPPER_CASE_CONSTANT = {
1222
+ relevance: 0,
1223
+ match: /\b[A-Z][A-Z_0-9]+\b/,
1224
+ className: "variable.constant"
1225
+ };
1226
+ function noneOf(list) {
1227
+ return regex.concat("(?!", list.join("|"), ")");
1228
+ }
1229
+ const FUNCTION_CALL = {
1230
+ match: regex.concat(
1231
+ /\b/,
1232
+ noneOf([
1233
+ ...BUILT_IN_GLOBALS,
1234
+ "super",
1235
+ "import",
1236
+ "await"
1237
+ ].map((x) => `${x}\\s*\\(`)),
1238
+ IDENT_RE$1,
1239
+ regex.lookahead(/\s*\(/)
1240
+ ),
1241
+ className: "title.function",
1242
+ relevance: 0
1243
+ };
1244
+ const PROPERTY_ACCESS = {
1245
+ begin: regex.concat(/\./, regex.lookahead(
1246
+ regex.concat(IDENT_RE$1, /(?![0-9A-Za-z$_(])/)
1247
+ )),
1248
+ end: IDENT_RE$1,
1249
+ excludeBegin: true,
1250
+ keywords: "prototype",
1251
+ className: "property",
1252
+ relevance: 0
1253
+ };
1254
+ const GETTER_OR_SETTER = {
1255
+ match: [
1256
+ /get|set/,
1257
+ /\s+/,
1258
+ IDENT_RE$1,
1259
+ /(?=\()/
1260
+ ],
1261
+ className: {
1262
+ 1: "keyword",
1263
+ 3: "title.function"
1264
+ },
1265
+ contains: [
1266
+ {
1267
+ // eat to avoid empty params
1268
+ begin: /\(\)/
1269
+ },
1270
+ PARAMS
1271
+ ]
1272
+ };
1273
+ const FUNC_LEAD_IN_RE = "(\\([^()]*(\\([^()]*(\\([^()]*\\)[^()]*)*\\)[^()]*)*\\)|" + hljs.UNDERSCORE_IDENT_RE + ")\\s*=>";
1274
+ const FUNCTION_VARIABLE = {
1275
+ match: [
1276
+ /const|var|let/,
1277
+ /\s+/,
1278
+ IDENT_RE$1,
1279
+ /\s*/,
1280
+ /=\s*/,
1281
+ /(async\s*)?/,
1282
+ // async is optional
1283
+ regex.lookahead(FUNC_LEAD_IN_RE)
1284
+ ],
1285
+ keywords: "async",
1286
+ className: {
1287
+ 1: "keyword",
1288
+ 3: "title.function"
1289
+ },
1290
+ contains: [
1291
+ PARAMS
1292
+ ]
1293
+ };
1294
+ return {
1295
+ name: "JavaScript",
1296
+ aliases: ["js", "jsx", "mjs", "cjs"],
1297
+ keywords: KEYWORDS$1,
1298
+ // this will be extended by TypeScript
1299
+ exports: { PARAMS_CONTAINS, CLASS_REFERENCE },
1300
+ illegal: /#(?![$_A-Za-z])/,
1301
+ contains: [
1302
+ hljs.SHEBANG({
1303
+ label: "shebang",
1304
+ binary: "node",
1305
+ relevance: 5
1306
+ }),
1307
+ USE_STRICT,
1308
+ hljs.APOS_STRING_MODE,
1309
+ hljs.QUOTE_STRING_MODE,
1310
+ HTML_TEMPLATE,
1311
+ CSS_TEMPLATE,
1312
+ GRAPHQL_TEMPLATE,
1313
+ TEMPLATE_STRING,
1314
+ COMMENT,
1315
+ // Skip numbers when they are part of a variable name
1316
+ { match: /\$\d+/ },
1317
+ NUMBER,
1318
+ CLASS_REFERENCE,
1319
+ {
1320
+ scope: "attr",
1321
+ match: IDENT_RE$1 + regex.lookahead(":"),
1322
+ relevance: 0
1323
+ },
1324
+ FUNCTION_VARIABLE,
1325
+ {
1326
+ // "value" container
1327
+ begin: "(" + hljs.RE_STARTERS_RE + "|\\b(case|return|throw)\\b)\\s*",
1328
+ keywords: "return throw case",
1329
+ relevance: 0,
1330
+ contains: [
1331
+ COMMENT,
1332
+ hljs.REGEXP_MODE,
1333
+ {
1334
+ className: "function",
1335
+ // we have to count the parens to make sure we actually have the
1336
+ // correct bounding ( ) before the =>. There could be any number of
1337
+ // sub-expressions inside also surrounded by parens.
1338
+ begin: FUNC_LEAD_IN_RE,
1339
+ returnBegin: true,
1340
+ end: "\\s*=>",
1341
+ contains: [
1342
+ {
1343
+ className: "params",
1344
+ variants: [
1345
+ {
1346
+ begin: hljs.UNDERSCORE_IDENT_RE,
1347
+ relevance: 0
1348
+ },
1349
+ {
1350
+ className: null,
1351
+ begin: /\(\s*\)/,
1352
+ skip: true
1353
+ },
1354
+ {
1355
+ begin: /(\s*)\(/,
1356
+ end: /\)/,
1357
+ excludeBegin: true,
1358
+ excludeEnd: true,
1359
+ keywords: KEYWORDS$1,
1360
+ contains: PARAMS_CONTAINS
1361
+ }
1362
+ ]
1363
+ }
1364
+ ]
1365
+ },
1366
+ {
1367
+ // could be a comma delimited list of params to a function call
1368
+ begin: /,/,
1369
+ relevance: 0
1370
+ },
1371
+ {
1372
+ match: /\s+/,
1373
+ relevance: 0
1374
+ },
1375
+ {
1376
+ // JSX
1377
+ variants: [
1378
+ { begin: FRAGMENT.begin, end: FRAGMENT.end },
1379
+ { match: XML_SELF_CLOSING },
1380
+ {
1381
+ begin: XML_TAG.begin,
1382
+ // we carefully check the opening tag to see if it truly
1383
+ // is a tag and not a false positive
1384
+ "on:begin": XML_TAG.isTrulyOpeningTag,
1385
+ end: XML_TAG.end
1386
+ }
1387
+ ],
1388
+ subLanguage: "xml",
1389
+ contains: [
1390
+ {
1391
+ begin: XML_TAG.begin,
1392
+ end: XML_TAG.end,
1393
+ skip: true,
1394
+ contains: ["self"]
1395
+ }
1396
+ ]
1397
+ }
1398
+ ]
1399
+ },
1400
+ FUNCTION_DEFINITION,
1401
+ {
1402
+ // prevent this from getting swallowed up by function
1403
+ // since they appear "function like"
1404
+ beginKeywords: "while if switch catch for"
1405
+ },
1406
+ {
1407
+ // we have to count the parens to make sure we actually have the correct
1408
+ // bounding ( ). There could be any number of sub-expressions inside
1409
+ // also surrounded by parens.
1410
+ begin: "\\b(?!function)" + hljs.UNDERSCORE_IDENT_RE + "\\([^()]*(\\([^()]*(\\([^()]*\\)[^()]*)*\\)[^()]*)*\\)\\s*\\{",
1411
+ // end parens
1412
+ returnBegin: true,
1413
+ label: "func.def",
1414
+ contains: [
1415
+ PARAMS,
1416
+ hljs.inherit(hljs.TITLE_MODE, { begin: IDENT_RE$1, className: "title.function" })
1417
+ ]
1418
+ },
1419
+ // catch ... so it won't trigger the property rule below
1420
+ {
1421
+ match: /\.\.\./,
1422
+ relevance: 0
1423
+ },
1424
+ PROPERTY_ACCESS,
1425
+ // hack: prevents detection of keywords in some circumstances
1426
+ // .keyword()
1427
+ // $keyword = x
1428
+ {
1429
+ match: "\\$" + IDENT_RE$1,
1430
+ relevance: 0
1431
+ },
1432
+ {
1433
+ match: [/\bconstructor(?=\s*\()/],
1434
+ className: { 1: "title.function" },
1435
+ contains: [PARAMS]
1436
+ },
1437
+ FUNCTION_CALL,
1438
+ UPPER_CASE_CONSTANT,
1439
+ CLASS_OR_EXTENDS,
1440
+ GETTER_OR_SETTER,
1441
+ {
1442
+ match: /\$[(.]/
1443
+ // relevance booster for a pattern common to JS libs: `$(something)` and `$.something`
1444
+ }
1445
+ ]
1446
+ };
1447
+ }
1448
+ function typescript(hljs) {
1449
+ const regex = hljs.regex;
1450
+ const tsLanguage = javascript(hljs);
1451
+ const IDENT_RE$1 = IDENT_RE;
1452
+ const TYPES3 = [
1453
+ "any",
1454
+ "void",
1455
+ "number",
1456
+ "boolean",
1457
+ "string",
1458
+ "object",
1459
+ "never",
1460
+ "symbol",
1461
+ "bigint",
1462
+ "unknown"
1463
+ ];
1464
+ const NAMESPACE = {
1465
+ begin: [
1466
+ /namespace/,
1467
+ /\s+/,
1468
+ hljs.IDENT_RE
1469
+ ],
1470
+ beginScope: {
1471
+ 1: "keyword",
1472
+ 3: "title.class"
1473
+ }
1474
+ };
1475
+ const INTERFACE = {
1476
+ beginKeywords: "interface",
1477
+ end: /\{/,
1478
+ excludeEnd: true,
1479
+ keywords: {
1480
+ keyword: "interface extends",
1481
+ built_in: TYPES3
1482
+ },
1483
+ contains: [tsLanguage.exports.CLASS_REFERENCE]
1484
+ };
1485
+ const USE_STRICT = {
1486
+ className: "meta",
1487
+ relevance: 10,
1488
+ begin: /^\s*['"]use strict['"]/
1489
+ };
1490
+ const TS_SPECIFIC_KEYWORDS = [
1491
+ "type",
1492
+ // "namespace",
1493
+ "interface",
1494
+ "public",
1495
+ "private",
1496
+ "protected",
1497
+ "implements",
1498
+ "declare",
1499
+ "abstract",
1500
+ "readonly",
1501
+ "enum",
1502
+ "override",
1503
+ "satisfies"
1504
+ ];
1505
+ const KEYWORDS$1 = {
1506
+ $pattern: IDENT_RE,
1507
+ keyword: KEYWORDS.concat(TS_SPECIFIC_KEYWORDS),
1508
+ literal: LITERALS,
1509
+ built_in: BUILT_INS.concat(TYPES3),
1510
+ "variable.language": BUILT_IN_VARIABLES
1511
+ };
1512
+ const DECORATOR = {
1513
+ className: "meta",
1514
+ begin: "@" + IDENT_RE$1
1515
+ };
1516
+ const swapMode = (mode, label, replacement) => {
1517
+ const indx = mode.contains.findIndex((m) => m.label === label);
1518
+ if (indx === -1) {
1519
+ throw new Error("can not find mode to replace");
1520
+ }
1521
+ mode.contains.splice(indx, 1, replacement);
1522
+ };
1523
+ Object.assign(tsLanguage.keywords, KEYWORDS$1);
1524
+ tsLanguage.exports.PARAMS_CONTAINS.push(DECORATOR);
1525
+ const ATTRIBUTE_HIGHLIGHT = tsLanguage.contains.find((c) => c.scope === "attr");
1526
+ const OPTIONAL_KEY_OR_ARGUMENT = Object.assign(
1527
+ {},
1528
+ ATTRIBUTE_HIGHLIGHT,
1529
+ { match: regex.concat(IDENT_RE$1, regex.lookahead(/\s*\?:/)) }
1530
+ );
1531
+ tsLanguage.exports.PARAMS_CONTAINS.push([
1532
+ tsLanguage.exports.CLASS_REFERENCE,
1533
+ // class reference for highlighting the params types
1534
+ ATTRIBUTE_HIGHLIGHT,
1535
+ // highlight the params key
1536
+ OPTIONAL_KEY_OR_ARGUMENT
1537
+ // Added for optional property assignment highlighting
1538
+ ]);
1539
+ tsLanguage.contains = tsLanguage.contains.concat([
1540
+ DECORATOR,
1541
+ NAMESPACE,
1542
+ INTERFACE,
1543
+ OPTIONAL_KEY_OR_ARGUMENT
1544
+ // Added for optional property assignment highlighting
1545
+ ]);
1546
+ swapMode(tsLanguage, "shebang", hljs.SHEBANG());
1547
+ swapMode(tsLanguage, "use_strict", USE_STRICT);
1548
+ const functionDeclaration = tsLanguage.contains.find((m) => m.label === "func.def");
1549
+ functionDeclaration.relevance = 0;
1550
+ Object.assign(tsLanguage, {
1551
+ name: "TypeScript",
1552
+ aliases: [
1553
+ "ts",
1554
+ "tsx",
1555
+ "mts",
1556
+ "cts"
1557
+ ]
1558
+ });
1559
+ return tsLanguage;
1560
+ }
1561
+
1562
+ // node_modules/highlight.js/es/languages/javascript.js
1563
+ var IDENT_RE2 = "[A-Za-z$_][0-9A-Za-z$_]*";
1564
+ var KEYWORDS2 = [
1565
+ "as",
1566
+ // for exports
1567
+ "in",
1568
+ "of",
1569
+ "if",
1570
+ "for",
1571
+ "while",
1572
+ "finally",
1573
+ "var",
1574
+ "new",
1575
+ "function",
1576
+ "do",
1577
+ "return",
1578
+ "void",
1579
+ "else",
1580
+ "break",
1581
+ "catch",
1582
+ "instanceof",
1583
+ "with",
1584
+ "throw",
1585
+ "case",
1586
+ "default",
1587
+ "try",
1588
+ "switch",
1589
+ "continue",
1590
+ "typeof",
1591
+ "delete",
1592
+ "let",
1593
+ "yield",
1594
+ "const",
1595
+ "class",
1596
+ // JS handles these with a special rule
1597
+ // "get",
1598
+ // "set",
1599
+ "debugger",
1600
+ "async",
1601
+ "await",
1602
+ "static",
1603
+ "import",
1604
+ "from",
1605
+ "export",
1606
+ "extends",
1607
+ // It's reached stage 3, which is "recommended for implementation":
1608
+ "using"
1609
+ ];
1610
+ var LITERALS2 = [
1611
+ "true",
1612
+ "false",
1613
+ "null",
1614
+ "undefined",
1615
+ "NaN",
1616
+ "Infinity"
1617
+ ];
1618
+ var TYPES2 = [
1619
+ // Fundamental objects
1620
+ "Object",
1621
+ "Function",
1622
+ "Boolean",
1623
+ "Symbol",
1624
+ // numbers and dates
1625
+ "Math",
1626
+ "Date",
1627
+ "Number",
1628
+ "BigInt",
1629
+ // text
1630
+ "String",
1631
+ "RegExp",
1632
+ // Indexed collections
1633
+ "Array",
1634
+ "Float32Array",
1635
+ "Float64Array",
1636
+ "Int8Array",
1637
+ "Uint8Array",
1638
+ "Uint8ClampedArray",
1639
+ "Int16Array",
1640
+ "Int32Array",
1641
+ "Uint16Array",
1642
+ "Uint32Array",
1643
+ "BigInt64Array",
1644
+ "BigUint64Array",
1645
+ // Keyed collections
1646
+ "Set",
1647
+ "Map",
1648
+ "WeakSet",
1649
+ "WeakMap",
1650
+ // Structured data
1651
+ "ArrayBuffer",
1652
+ "SharedArrayBuffer",
1653
+ "Atomics",
1654
+ "DataView",
1655
+ "JSON",
1656
+ // Control abstraction objects
1657
+ "Promise",
1658
+ "Generator",
1659
+ "GeneratorFunction",
1660
+ "AsyncFunction",
1661
+ // Reflection
1662
+ "Reflect",
1663
+ "Proxy",
1664
+ // Internationalization
1665
+ "Intl",
1666
+ // WebAssembly
1667
+ "WebAssembly"
1668
+ ];
1669
+ var ERROR_TYPES2 = [
1670
+ "Error",
1671
+ "EvalError",
1672
+ "InternalError",
1673
+ "RangeError",
1674
+ "ReferenceError",
1675
+ "SyntaxError",
1676
+ "TypeError",
1677
+ "URIError"
1678
+ ];
1679
+ var BUILT_IN_GLOBALS2 = [
1680
+ "setInterval",
1681
+ "setTimeout",
1682
+ "clearInterval",
1683
+ "clearTimeout",
1684
+ "require",
1685
+ "exports",
1686
+ "eval",
1687
+ "isFinite",
1688
+ "isNaN",
1689
+ "parseFloat",
1690
+ "parseInt",
1691
+ "decodeURI",
1692
+ "decodeURIComponent",
1693
+ "encodeURI",
1694
+ "encodeURIComponent",
1695
+ "escape",
1696
+ "unescape"
1697
+ ];
1698
+ var BUILT_IN_VARIABLES2 = [
1699
+ "arguments",
1700
+ "this",
1701
+ "super",
1702
+ "console",
1703
+ "window",
1704
+ "document",
1705
+ "localStorage",
1706
+ "sessionStorage",
1707
+ "module",
1708
+ "self",
1709
+ "global"
1710
+ // Node.js
1711
+ ];
1712
+ var BUILT_INS2 = [].concat(
1713
+ BUILT_IN_GLOBALS2,
1714
+ TYPES2,
1715
+ ERROR_TYPES2
1716
+ );
1717
+ function javascript2(hljs) {
1718
+ const regex = hljs.regex;
1719
+ const hasClosingTag = (match, { after }) => {
1720
+ const tag = "</" + match[0].slice(1);
1721
+ const pos = match.input.indexOf(tag, after);
1722
+ return pos !== -1;
1723
+ };
1724
+ const IDENT_RE$1 = IDENT_RE2;
1725
+ const FRAGMENT = {
1726
+ begin: "<>",
1727
+ end: "</>"
1728
+ };
1729
+ const XML_SELF_CLOSING = /<[A-Za-z0-9\\._:-]+\s*\/>/;
1730
+ const XML_TAG = {
1731
+ begin: /<[A-Za-z0-9\\._:-]+/,
1732
+ end: /\/[A-Za-z0-9\\._:-]+>|\/>/,
1733
+ /**
1734
+ * @param {RegExpMatchArray} match
1735
+ * @param {CallbackResponse} response
1736
+ */
1737
+ isTrulyOpeningTag: (match, response) => {
1738
+ const afterMatchIndex = match[0].length + match.index;
1739
+ const nextChar = match.input[afterMatchIndex];
1740
+ if (
1741
+ // HTML should not include another raw `<` inside a tag
1742
+ // nested type?
1743
+ // `<Array<Array<number>>`, etc.
1744
+ nextChar === "<" || // the , gives away that this is not HTML
1745
+ // `<T, A extends keyof T, V>`
1746
+ nextChar === ","
1747
+ ) {
1748
+ response.ignoreMatch();
1749
+ return;
1750
+ }
1751
+ if (nextChar === ">") {
1752
+ if (!hasClosingTag(match, { after: afterMatchIndex })) {
1753
+ response.ignoreMatch();
1754
+ }
1755
+ }
1756
+ let m;
1757
+ const afterMatch = match.input.substring(afterMatchIndex);
1758
+ if (m = afterMatch.match(/^\s*=/)) {
1759
+ response.ignoreMatch();
1760
+ return;
1761
+ }
1762
+ if (m = afterMatch.match(/^\s+extends\s+/)) {
1763
+ if (m.index === 0) {
1764
+ response.ignoreMatch();
1765
+ return;
1766
+ }
1767
+ }
1768
+ }
1769
+ };
1770
+ const KEYWORDS$1 = {
1771
+ $pattern: IDENT_RE2,
1772
+ keyword: KEYWORDS2,
1773
+ literal: LITERALS2,
1774
+ built_in: BUILT_INS2,
1775
+ "variable.language": BUILT_IN_VARIABLES2
1776
+ };
1777
+ const decimalDigits2 = "[0-9](_?[0-9])*";
1778
+ const frac2 = `\\.(${decimalDigits2})`;
1779
+ const decimalInteger = `0|[1-9](_?[0-9])*|0[0-7]*[89][0-9]*`;
1780
+ const NUMBER = {
1781
+ className: "number",
1782
+ variants: [
1783
+ // DecimalLiteral
1784
+ { begin: `(\\b(${decimalInteger})((${frac2})|\\.)?|(${frac2}))[eE][+-]?(${decimalDigits2})\\b` },
1785
+ { begin: `\\b(${decimalInteger})\\b((${frac2})\\b|\\.)?|(${frac2})\\b` },
1786
+ // DecimalBigIntegerLiteral
1787
+ { begin: `\\b(0|[1-9](_?[0-9])*)n\\b` },
1788
+ // NonDecimalIntegerLiteral
1789
+ { begin: "\\b0[xX][0-9a-fA-F](_?[0-9a-fA-F])*n?\\b" },
1790
+ { begin: "\\b0[bB][0-1](_?[0-1])*n?\\b" },
1791
+ { begin: "\\b0[oO][0-7](_?[0-7])*n?\\b" },
1792
+ // LegacyOctalIntegerLiteral (does not include underscore separators)
1793
+ // https://tc39.es/ecma262/#sec-additional-syntax-numeric-literals
1794
+ { begin: "\\b0[0-7]+n?\\b" }
1795
+ ],
1796
+ relevance: 0
1797
+ };
1798
+ const SUBST = {
1799
+ className: "subst",
1800
+ begin: "\\$\\{",
1801
+ end: "\\}",
1802
+ keywords: KEYWORDS$1,
1803
+ contains: []
1804
+ // defined later
1805
+ };
1806
+ const HTML_TEMPLATE = {
1807
+ begin: ".?html`",
1808
+ end: "",
1809
+ starts: {
1810
+ end: "`",
1811
+ returnEnd: false,
1812
+ contains: [
1813
+ hljs.BACKSLASH_ESCAPE,
1814
+ SUBST
1815
+ ],
1816
+ subLanguage: "xml"
1817
+ }
1818
+ };
1819
+ const CSS_TEMPLATE = {
1820
+ begin: ".?css`",
1821
+ end: "",
1822
+ starts: {
1823
+ end: "`",
1824
+ returnEnd: false,
1825
+ contains: [
1826
+ hljs.BACKSLASH_ESCAPE,
1827
+ SUBST
1828
+ ],
1829
+ subLanguage: "css"
1830
+ }
1831
+ };
1832
+ const GRAPHQL_TEMPLATE = {
1833
+ begin: ".?gql`",
1834
+ end: "",
1835
+ starts: {
1836
+ end: "`",
1837
+ returnEnd: false,
1838
+ contains: [
1839
+ hljs.BACKSLASH_ESCAPE,
1840
+ SUBST
1841
+ ],
1842
+ subLanguage: "graphql"
1843
+ }
1844
+ };
1845
+ const TEMPLATE_STRING = {
1846
+ className: "string",
1847
+ begin: "`",
1848
+ end: "`",
1849
+ contains: [
1850
+ hljs.BACKSLASH_ESCAPE,
1851
+ SUBST
1852
+ ]
1853
+ };
1854
+ const JSDOC_COMMENT = hljs.COMMENT(
1855
+ /\/\*\*(?!\/)/,
1856
+ "\\*/",
1857
+ {
1858
+ relevance: 0,
1859
+ contains: [
1860
+ {
1861
+ begin: "(?=@[A-Za-z]+)",
1862
+ relevance: 0,
1863
+ contains: [
1864
+ {
1865
+ className: "doctag",
1866
+ begin: "@[A-Za-z]+"
1867
+ },
1868
+ {
1869
+ className: "type",
1870
+ begin: "\\{",
1871
+ end: "\\}",
1872
+ excludeEnd: true,
1873
+ excludeBegin: true,
1874
+ relevance: 0
1875
+ },
1876
+ {
1877
+ className: "variable",
1878
+ begin: IDENT_RE$1 + "(?=\\s*(-)|$)",
1879
+ endsParent: true,
1880
+ relevance: 0
1881
+ },
1882
+ // eat spaces (not newlines) so we can find
1883
+ // types or variables
1884
+ {
1885
+ begin: /(?=[^\n])\s/,
1886
+ relevance: 0
1887
+ }
1888
+ ]
1889
+ }
1890
+ ]
1891
+ }
1892
+ );
1893
+ const COMMENT = {
1894
+ className: "comment",
1895
+ variants: [
1896
+ JSDOC_COMMENT,
1897
+ hljs.C_BLOCK_COMMENT_MODE,
1898
+ hljs.C_LINE_COMMENT_MODE
1899
+ ]
1900
+ };
1901
+ const SUBST_INTERNALS = [
1902
+ hljs.APOS_STRING_MODE,
1903
+ hljs.QUOTE_STRING_MODE,
1904
+ HTML_TEMPLATE,
1905
+ CSS_TEMPLATE,
1906
+ GRAPHQL_TEMPLATE,
1907
+ TEMPLATE_STRING,
1908
+ // Skip numbers when they are part of a variable name
1909
+ { match: /\$\d+/ },
1910
+ NUMBER
1911
+ // This is intentional:
1912
+ // See https://github.com/highlightjs/highlight.js/issues/3288
1913
+ // hljs.REGEXP_MODE
1914
+ ];
1915
+ SUBST.contains = SUBST_INTERNALS.concat({
1916
+ // we need to pair up {} inside our subst to prevent
1917
+ // it from ending too early by matching another }
1918
+ begin: /\{/,
1919
+ end: /\}/,
1920
+ keywords: KEYWORDS$1,
1921
+ contains: [
1922
+ "self"
1923
+ ].concat(SUBST_INTERNALS)
1924
+ });
1925
+ const SUBST_AND_COMMENTS = [].concat(COMMENT, SUBST.contains);
1926
+ const PARAMS_CONTAINS = SUBST_AND_COMMENTS.concat([
1927
+ // eat recursive parens in sub expressions
1928
+ {
1929
+ begin: /(\s*)\(/,
1930
+ end: /\)/,
1931
+ keywords: KEYWORDS$1,
1932
+ contains: ["self"].concat(SUBST_AND_COMMENTS)
1933
+ }
1934
+ ]);
1935
+ const PARAMS = {
1936
+ className: "params",
1937
+ // convert this to negative lookbehind in v12
1938
+ begin: /(\s*)\(/,
1939
+ // to match the parms with
1940
+ end: /\)/,
1941
+ excludeBegin: true,
1942
+ excludeEnd: true,
1943
+ keywords: KEYWORDS$1,
1944
+ contains: PARAMS_CONTAINS
1945
+ };
1946
+ const CLASS_OR_EXTENDS = {
1947
+ variants: [
1948
+ // class Car extends vehicle
1949
+ {
1950
+ match: [
1951
+ /class/,
1952
+ /\s+/,
1953
+ IDENT_RE$1,
1954
+ /\s+/,
1955
+ /extends/,
1956
+ /\s+/,
1957
+ regex.concat(IDENT_RE$1, "(", regex.concat(/\./, IDENT_RE$1), ")*")
1958
+ ],
1959
+ scope: {
1960
+ 1: "keyword",
1961
+ 3: "title.class",
1962
+ 5: "keyword",
1963
+ 7: "title.class.inherited"
1964
+ }
1965
+ },
1966
+ // class Car
1967
+ {
1968
+ match: [
1969
+ /class/,
1970
+ /\s+/,
1971
+ IDENT_RE$1
1972
+ ],
1973
+ scope: {
1974
+ 1: "keyword",
1975
+ 3: "title.class"
1976
+ }
1977
+ }
1978
+ ]
1979
+ };
1980
+ const CLASS_REFERENCE = {
1981
+ relevance: 0,
1982
+ match: regex.either(
1983
+ // Hard coded exceptions
1984
+ /\bJSON/,
1985
+ // Float32Array, OutT
1986
+ /\b[A-Z][a-z]+([A-Z][a-z]*|\d)*/,
1987
+ // CSSFactory, CSSFactoryT
1988
+ /\b[A-Z]{2,}([A-Z][a-z]+|\d)+([A-Z][a-z]*)*/,
1989
+ // FPs, FPsT
1990
+ /\b[A-Z]{2,}[a-z]+([A-Z][a-z]+|\d)*([A-Z][a-z]*)*/
1991
+ // P
1992
+ // single letters are not highlighted
1993
+ // BLAH
1994
+ // this will be flagged as a UPPER_CASE_CONSTANT instead
1995
+ ),
1996
+ className: "title.class",
1997
+ keywords: {
1998
+ _: [
1999
+ // se we still get relevance credit for JS library classes
2000
+ ...TYPES2,
2001
+ ...ERROR_TYPES2
2002
+ ]
2003
+ }
2004
+ };
2005
+ const USE_STRICT = {
2006
+ label: "use_strict",
2007
+ className: "meta",
2008
+ relevance: 10,
2009
+ begin: /^\s*['"]use (strict|asm)['"]/
2010
+ };
2011
+ const FUNCTION_DEFINITION = {
2012
+ variants: [
2013
+ {
2014
+ match: [
2015
+ /function/,
2016
+ /\s+/,
2017
+ IDENT_RE$1,
2018
+ /(?=\s*\()/
2019
+ ]
2020
+ },
2021
+ // anonymous function
2022
+ {
2023
+ match: [
2024
+ /function/,
2025
+ /\s*(?=\()/
2026
+ ]
2027
+ }
2028
+ ],
2029
+ className: {
2030
+ 1: "keyword",
2031
+ 3: "title.function"
2032
+ },
2033
+ label: "func.def",
2034
+ contains: [PARAMS],
2035
+ illegal: /%/
2036
+ };
2037
+ const UPPER_CASE_CONSTANT = {
2038
+ relevance: 0,
2039
+ match: /\b[A-Z][A-Z_0-9]+\b/,
2040
+ className: "variable.constant"
2041
+ };
2042
+ function noneOf(list) {
2043
+ return regex.concat("(?!", list.join("|"), ")");
2044
+ }
2045
+ const FUNCTION_CALL = {
2046
+ match: regex.concat(
2047
+ /\b/,
2048
+ noneOf([
2049
+ ...BUILT_IN_GLOBALS2,
2050
+ "super",
2051
+ "import",
2052
+ "await"
2053
+ ].map((x) => `${x}\\s*\\(`)),
2054
+ IDENT_RE$1,
2055
+ regex.lookahead(/\s*\(/)
2056
+ ),
2057
+ className: "title.function",
2058
+ relevance: 0
2059
+ };
2060
+ const PROPERTY_ACCESS = {
2061
+ begin: regex.concat(/\./, regex.lookahead(
2062
+ regex.concat(IDENT_RE$1, /(?![0-9A-Za-z$_(])/)
2063
+ )),
2064
+ end: IDENT_RE$1,
2065
+ excludeBegin: true,
2066
+ keywords: "prototype",
2067
+ className: "property",
2068
+ relevance: 0
2069
+ };
2070
+ const GETTER_OR_SETTER = {
2071
+ match: [
2072
+ /get|set/,
2073
+ /\s+/,
2074
+ IDENT_RE$1,
2075
+ /(?=\()/
2076
+ ],
2077
+ className: {
2078
+ 1: "keyword",
2079
+ 3: "title.function"
2080
+ },
2081
+ contains: [
2082
+ {
2083
+ // eat to avoid empty params
2084
+ begin: /\(\)/
2085
+ },
2086
+ PARAMS
2087
+ ]
2088
+ };
2089
+ const FUNC_LEAD_IN_RE = "(\\([^()]*(\\([^()]*(\\([^()]*\\)[^()]*)*\\)[^()]*)*\\)|" + hljs.UNDERSCORE_IDENT_RE + ")\\s*=>";
2090
+ const FUNCTION_VARIABLE = {
2091
+ match: [
2092
+ /const|var|let/,
2093
+ /\s+/,
2094
+ IDENT_RE$1,
2095
+ /\s*/,
2096
+ /=\s*/,
2097
+ /(async\s*)?/,
2098
+ // async is optional
2099
+ regex.lookahead(FUNC_LEAD_IN_RE)
2100
+ ],
2101
+ keywords: "async",
2102
+ className: {
2103
+ 1: "keyword",
2104
+ 3: "title.function"
2105
+ },
2106
+ contains: [
2107
+ PARAMS
2108
+ ]
2109
+ };
2110
+ return {
2111
+ name: "JavaScript",
2112
+ aliases: ["js", "jsx", "mjs", "cjs"],
2113
+ keywords: KEYWORDS$1,
2114
+ // this will be extended by TypeScript
2115
+ exports: { PARAMS_CONTAINS, CLASS_REFERENCE },
2116
+ illegal: /#(?![$_A-Za-z])/,
2117
+ contains: [
2118
+ hljs.SHEBANG({
2119
+ label: "shebang",
2120
+ binary: "node",
2121
+ relevance: 5
2122
+ }),
2123
+ USE_STRICT,
2124
+ hljs.APOS_STRING_MODE,
2125
+ hljs.QUOTE_STRING_MODE,
2126
+ HTML_TEMPLATE,
2127
+ CSS_TEMPLATE,
2128
+ GRAPHQL_TEMPLATE,
2129
+ TEMPLATE_STRING,
2130
+ COMMENT,
2131
+ // Skip numbers when they are part of a variable name
2132
+ { match: /\$\d+/ },
2133
+ NUMBER,
2134
+ CLASS_REFERENCE,
2135
+ {
2136
+ scope: "attr",
2137
+ match: IDENT_RE$1 + regex.lookahead(":"),
2138
+ relevance: 0
2139
+ },
2140
+ FUNCTION_VARIABLE,
2141
+ {
2142
+ // "value" container
2143
+ begin: "(" + hljs.RE_STARTERS_RE + "|\\b(case|return|throw)\\b)\\s*",
2144
+ keywords: "return throw case",
2145
+ relevance: 0,
2146
+ contains: [
2147
+ COMMENT,
2148
+ hljs.REGEXP_MODE,
2149
+ {
2150
+ className: "function",
2151
+ // we have to count the parens to make sure we actually have the
2152
+ // correct bounding ( ) before the =>. There could be any number of
2153
+ // sub-expressions inside also surrounded by parens.
2154
+ begin: FUNC_LEAD_IN_RE,
2155
+ returnBegin: true,
2156
+ end: "\\s*=>",
2157
+ contains: [
2158
+ {
2159
+ className: "params",
2160
+ variants: [
2161
+ {
2162
+ begin: hljs.UNDERSCORE_IDENT_RE,
2163
+ relevance: 0
2164
+ },
2165
+ {
2166
+ className: null,
2167
+ begin: /\(\s*\)/,
2168
+ skip: true
2169
+ },
2170
+ {
2171
+ begin: /(\s*)\(/,
2172
+ end: /\)/,
2173
+ excludeBegin: true,
2174
+ excludeEnd: true,
2175
+ keywords: KEYWORDS$1,
2176
+ contains: PARAMS_CONTAINS
2177
+ }
2178
+ ]
2179
+ }
2180
+ ]
2181
+ },
2182
+ {
2183
+ // could be a comma delimited list of params to a function call
2184
+ begin: /,/,
2185
+ relevance: 0
2186
+ },
2187
+ {
2188
+ match: /\s+/,
2189
+ relevance: 0
2190
+ },
2191
+ {
2192
+ // JSX
2193
+ variants: [
2194
+ { begin: FRAGMENT.begin, end: FRAGMENT.end },
2195
+ { match: XML_SELF_CLOSING },
2196
+ {
2197
+ begin: XML_TAG.begin,
2198
+ // we carefully check the opening tag to see if it truly
2199
+ // is a tag and not a false positive
2200
+ "on:begin": XML_TAG.isTrulyOpeningTag,
2201
+ end: XML_TAG.end
2202
+ }
2203
+ ],
2204
+ subLanguage: "xml",
2205
+ contains: [
2206
+ {
2207
+ begin: XML_TAG.begin,
2208
+ end: XML_TAG.end,
2209
+ skip: true,
2210
+ contains: ["self"]
2211
+ }
2212
+ ]
2213
+ }
2214
+ ]
2215
+ },
2216
+ FUNCTION_DEFINITION,
2217
+ {
2218
+ // prevent this from getting swallowed up by function
2219
+ // since they appear "function like"
2220
+ beginKeywords: "while if switch catch for"
2221
+ },
2222
+ {
2223
+ // we have to count the parens to make sure we actually have the correct
2224
+ // bounding ( ). There could be any number of sub-expressions inside
2225
+ // also surrounded by parens.
2226
+ begin: "\\b(?!function)" + hljs.UNDERSCORE_IDENT_RE + "\\([^()]*(\\([^()]*(\\([^()]*\\)[^()]*)*\\)[^()]*)*\\)\\s*\\{",
2227
+ // end parens
2228
+ returnBegin: true,
2229
+ label: "func.def",
2230
+ contains: [
2231
+ PARAMS,
2232
+ hljs.inherit(hljs.TITLE_MODE, { begin: IDENT_RE$1, className: "title.function" })
2233
+ ]
2234
+ },
2235
+ // catch ... so it won't trigger the property rule below
2236
+ {
2237
+ match: /\.\.\./,
2238
+ relevance: 0
2239
+ },
2240
+ PROPERTY_ACCESS,
2241
+ // hack: prevents detection of keywords in some circumstances
2242
+ // .keyword()
2243
+ // $keyword = x
2244
+ {
2245
+ match: "\\$" + IDENT_RE$1,
2246
+ relevance: 0
2247
+ },
2248
+ {
2249
+ match: [/\bconstructor(?=\s*\()/],
2250
+ className: { 1: "title.function" },
2251
+ contains: [PARAMS]
2252
+ },
2253
+ FUNCTION_CALL,
2254
+ UPPER_CASE_CONSTANT,
2255
+ CLASS_OR_EXTENDS,
2256
+ GETTER_OR_SETTER,
2257
+ {
2258
+ match: /\$[(.]/
2259
+ // relevance booster for a pattern common to JS libs: `$(something)` and `$.something`
2260
+ }
2261
+ ]
2262
+ };
2263
+ }
2264
+
2265
+ // node_modules/highlight.js/es/languages/java.js
2266
+ var decimalDigits = "[0-9](_*[0-9])*";
2267
+ var frac = `\\.(${decimalDigits})`;
2268
+ var hexDigits = "[0-9a-fA-F](_*[0-9a-fA-F])*";
2269
+ var NUMERIC = {
2270
+ className: "number",
2271
+ variants: [
2272
+ // DecimalFloatingPointLiteral
2273
+ // including ExponentPart
2274
+ { begin: `(\\b(${decimalDigits})((${frac})|\\.)?|(${frac}))[eE][+-]?(${decimalDigits})[fFdD]?\\b` },
2275
+ // excluding ExponentPart
2276
+ { begin: `\\b(${decimalDigits})((${frac})[fFdD]?\\b|\\.([fFdD]\\b)?)` },
2277
+ { begin: `(${frac})[fFdD]?\\b` },
2278
+ { begin: `\\b(${decimalDigits})[fFdD]\\b` },
2279
+ // HexadecimalFloatingPointLiteral
2280
+ { begin: `\\b0[xX]((${hexDigits})\\.?|(${hexDigits})?\\.(${hexDigits}))[pP][+-]?(${decimalDigits})[fFdD]?\\b` },
2281
+ // DecimalIntegerLiteral
2282
+ { begin: "\\b(0|[1-9](_*[0-9])*)[lL]?\\b" },
2283
+ // HexIntegerLiteral
2284
+ { begin: `\\b0[xX](${hexDigits})[lL]?\\b` },
2285
+ // OctalIntegerLiteral
2286
+ { begin: "\\b0(_*[0-7])*[lL]?\\b" },
2287
+ // BinaryIntegerLiteral
2288
+ { begin: "\\b0[bB][01](_*[01])*[lL]?\\b" }
2289
+ ],
2290
+ relevance: 0
2291
+ };
2292
+ function recurRegex(re, substitution, depth) {
2293
+ if (depth === -1) return "";
2294
+ return re.replace(substitution, (_) => {
2295
+ return recurRegex(re, substitution, depth - 1);
2296
+ });
2297
+ }
2298
+ function java(hljs) {
2299
+ const regex = hljs.regex;
2300
+ const JAVA_IDENT_RE = "[\xC0-\u02B8a-zA-Z_$][\xC0-\u02B8a-zA-Z_$0-9]*";
2301
+ const ARRAY_BRACKETS_OPTIONAL_RE = "(?:(?:\\s*\\[\\s*])+)?";
2302
+ const SIMPLE_TYPE_RE = JAVA_IDENT_RE + "<@@@>" + ARRAY_BRACKETS_OPTIONAL_RE;
2303
+ const WILDCARD_TYPE_RE = "\\?(?:\\s+(?:extends|super)\\s+" + SIMPLE_TYPE_RE + ")?";
2304
+ const TYPE_ARG_RE = "(?:" + WILDCARD_TYPE_RE + "|" + SIMPLE_TYPE_RE + ")";
2305
+ const TYPE_ARGS_OPTIONAL_RE = recurRegex(
2306
+ "(?:\\s*<\\s*" + TYPE_ARG_RE + "(?:\\s*,\\s*" + TYPE_ARG_RE + ")*\\s*>)?",
2307
+ /<@@@>/g,
2308
+ 2
2309
+ );
2310
+ const MAIN_KEYWORDS = [
2311
+ "synchronized",
2312
+ "abstract",
2313
+ "private",
2314
+ "var",
2315
+ "static",
2316
+ "if",
2317
+ "const ",
2318
+ "for",
2319
+ "while",
2320
+ "strictfp",
2321
+ "finally",
2322
+ "protected",
2323
+ "import",
2324
+ "native",
2325
+ "final",
2326
+ "void",
2327
+ "enum",
2328
+ "else",
2329
+ "break",
2330
+ "transient",
2331
+ "catch",
2332
+ "instanceof",
2333
+ "volatile",
2334
+ "case",
2335
+ "assert",
2336
+ "package",
2337
+ "default",
2338
+ "public",
2339
+ "try",
2340
+ "switch",
2341
+ "continue",
2342
+ "throws",
2343
+ "protected",
2344
+ "public",
2345
+ "private",
2346
+ "module",
2347
+ "requires",
2348
+ "exports",
2349
+ "do",
2350
+ "sealed",
2351
+ "yield",
2352
+ "permits",
2353
+ "goto",
2354
+ "when"
2355
+ ];
2356
+ const BUILT_INS3 = [
2357
+ "super",
2358
+ "this"
2359
+ ];
2360
+ const LITERALS3 = [
2361
+ "false",
2362
+ "true",
2363
+ "null"
2364
+ ];
2365
+ const TYPES3 = [
2366
+ "char",
2367
+ "boolean",
2368
+ "long",
2369
+ "float",
2370
+ "int",
2371
+ "byte",
2372
+ "short",
2373
+ "double"
2374
+ ];
2375
+ const KEYWORDS3 = {
2376
+ keyword: MAIN_KEYWORDS,
2377
+ literal: LITERALS3,
2378
+ type: TYPES3,
2379
+ built_in: BUILT_INS3
2380
+ };
2381
+ const ANNOTATION = {
2382
+ className: "meta",
2383
+ begin: "@" + JAVA_IDENT_RE,
2384
+ contains: [
2385
+ {
2386
+ begin: /\(/,
2387
+ end: /\)/,
2388
+ contains: ["self"]
2389
+ // allow nested () inside our annotation
2390
+ }
2391
+ ]
2392
+ };
2393
+ const PARAMS = {
2394
+ className: "params",
2395
+ begin: /\(/,
2396
+ end: /\)/,
2397
+ keywords: KEYWORDS3,
2398
+ relevance: 0,
2399
+ contains: [hljs.C_BLOCK_COMMENT_MODE],
2400
+ endsParent: true
2401
+ };
2402
+ return {
2403
+ name: "Java",
2404
+ aliases: ["jsp"],
2405
+ keywords: KEYWORDS3,
2406
+ illegal: /<\/|#/,
2407
+ contains: [
2408
+ hljs.COMMENT(
2409
+ "/\\*\\*",
2410
+ "\\*/",
2411
+ {
2412
+ relevance: 0,
2413
+ contains: [
2414
+ {
2415
+ // eat up @'s in emails to prevent them to be recognized as doctags
2416
+ begin: /\w+@/,
2417
+ relevance: 0
2418
+ },
2419
+ {
2420
+ className: "doctag",
2421
+ begin: "@[A-Za-z]+"
2422
+ }
2423
+ ]
2424
+ }
2425
+ ),
2426
+ // relevance boost
2427
+ {
2428
+ begin: /import java\.[a-z]+\./,
2429
+ keywords: "import",
2430
+ relevance: 2
2431
+ },
2432
+ hljs.C_LINE_COMMENT_MODE,
2433
+ hljs.C_BLOCK_COMMENT_MODE,
2434
+ {
2435
+ begin: /"""/,
2436
+ end: /"""/,
2437
+ className: "string",
2438
+ contains: [hljs.BACKSLASH_ESCAPE]
2439
+ },
2440
+ hljs.APOS_STRING_MODE,
2441
+ hljs.QUOTE_STRING_MODE,
2442
+ {
2443
+ match: [
2444
+ /\b(?:class|interface|enum|extends|implements|new)/,
2445
+ /\s+/,
2446
+ JAVA_IDENT_RE
2447
+ ],
2448
+ className: {
2449
+ 1: "keyword",
2450
+ 3: "title.class"
2451
+ }
2452
+ },
2453
+ {
2454
+ // Exceptions for hyphenated keywords
2455
+ match: /non-sealed/,
2456
+ scope: "keyword"
2457
+ },
2458
+ {
2459
+ // Expression keywords prevent keyword-led expressions from being
2460
+ // recognized as variable or method declarations.
2461
+ beginKeywords: "new throw return else yield assert",
2462
+ relevance: 0
2463
+ },
2464
+ {
2465
+ begin: [
2466
+ JAVA_IDENT_RE,
2467
+ regex.concat(TYPE_ARGS_OPTIONAL_RE, ARRAY_BRACKETS_OPTIONAL_RE, /\s+/),
2468
+ JAVA_IDENT_RE,
2469
+ ARRAY_BRACKETS_OPTIONAL_RE,
2470
+ /\s*/,
2471
+ /=(?!=)/
2472
+ ],
2473
+ className: {
2474
+ 1: "type",
2475
+ 3: "variable",
2476
+ 6: "operator"
2477
+ }
2478
+ },
2479
+ {
2480
+ begin: [
2481
+ /record/,
2482
+ /\s+/,
2483
+ JAVA_IDENT_RE
2484
+ ],
2485
+ className: {
2486
+ 1: "keyword",
2487
+ 3: "title.class"
2488
+ },
2489
+ contains: [
2490
+ PARAMS,
2491
+ hljs.C_LINE_COMMENT_MODE,
2492
+ hljs.C_BLOCK_COMMENT_MODE
2493
+ ]
2494
+ },
2495
+ {
2496
+ begin: [
2497
+ JAVA_IDENT_RE,
2498
+ regex.concat(TYPE_ARGS_OPTIONAL_RE, ARRAY_BRACKETS_OPTIONAL_RE, /\s+/),
2499
+ JAVA_IDENT_RE,
2500
+ /\s*(?=\()/
2501
+ ],
2502
+ className: {
2503
+ 1: "type",
2504
+ 3: "title.function"
2505
+ },
2506
+ keywords: KEYWORDS3,
2507
+ contains: [
2508
+ {
2509
+ className: "params",
2510
+ begin: /\(/,
2511
+ end: /\)/,
2512
+ keywords: KEYWORDS3,
2513
+ relevance: 0,
2514
+ contains: [
2515
+ ANNOTATION,
2516
+ hljs.APOS_STRING_MODE,
2517
+ hljs.QUOTE_STRING_MODE,
2518
+ NUMERIC,
2519
+ hljs.C_BLOCK_COMMENT_MODE
2520
+ ]
2521
+ },
2522
+ hljs.C_LINE_COMMENT_MODE,
2523
+ hljs.C_BLOCK_COMMENT_MODE
2524
+ ]
2525
+ },
2526
+ NUMERIC,
2527
+ ANNOTATION
2528
+ ]
2529
+ };
2530
+ }
2531
+
2532
+ // src/components/MarkdownEditor/markdown/pipeline.ts
2533
+ var import_unified = require("unified");
2534
+ var import_remark_parse = __toESM(require("remark-parse"), 1);
2535
+ var import_remark_gfm = __toESM(require("remark-gfm"), 1);
2536
+ var import_remark_rehype = __toESM(require("remark-rehype"), 1);
2537
+ var import_remark_stringify = __toESM(require("remark-stringify"), 1);
2538
+ var import_rehype_stringify = __toESM(require("rehype-stringify"), 1);
2539
+ var import_rehype_parse = __toESM(require("rehype-parse"), 1);
2540
+ var import_rehype_raw = __toESM(require("rehype-raw"), 1);
2541
+ var import_rehype_remark = __toESM(require("rehype-remark"), 1);
2542
+ var import_rehype_sanitize = __toESM(require("rehype-sanitize"), 1);
2543
+ var import_rehype_highlight = __toESM(require("rehype-highlight"), 1);
2544
+ var import_unist_util_visit = require("unist-util-visit");
2545
+ var HIGHLIGHT_LANGUAGES = { json, sql, typescript, javascript: javascript2, java };
2546
+ var sanitizeSchemaWithHighlight = {
2547
+ ...import_rehype_sanitize.defaultSchema,
2548
+ attributes: {
2549
+ ...import_rehype_sanitize.defaultSchema.attributes,
2550
+ code: [...import_rehype_sanitize.defaultSchema.attributes?.code ?? [], "className"],
2551
+ span: [...import_rehype_sanitize.defaultSchema.attributes?.span ?? [], "className"]
2552
+ }
2553
+ };
2554
+ var STRINGIFY_OPTIONS = {
2555
+ bullet: "-",
2556
+ listItemIndent: "one",
2557
+ fences: true,
2558
+ rule: "-"
2559
+ };
2560
+ function isElement(node) {
2561
+ return node.type === "element";
2562
+ }
2563
+ function embedRawHtml() {
2564
+ return (tree) => {
2565
+ (0, import_unist_util_visit.visit)(tree, "html", (node, index, parent) => {
2566
+ if (parent === void 0 || index === void 0) return;
2567
+ if (parent.type === "paragraph") {
2568
+ parent.children[index] = { type: "text", value: node.value };
2569
+ } else {
2570
+ const placeholder = {
2571
+ type: "htmlEmbed",
2572
+ data: {
2573
+ hName: "div",
2574
+ hProperties: { dataRawHtml: encodeURIComponent(node.value) }
2575
+ }
2576
+ };
2577
+ parent.children[index] = placeholder;
2578
+ }
2579
+ });
2580
+ };
2581
+ }
2582
+ function taskListsToTiptap() {
2583
+ return (tree) => {
2584
+ (0, import_unist_util_visit.visit)(tree, "element", (node) => {
2585
+ if (node.tagName !== "li") return;
2586
+ const classes = Array.isArray(node.properties.className) ? node.properties.className : [];
2587
+ if (!classes.includes("task-list-item")) return;
2588
+ let checked = false;
2589
+ node.children = node.children.filter((child) => {
2590
+ if (isElement(child) && child.tagName === "input") {
2591
+ checked = child.properties.checked === true;
2592
+ return false;
2593
+ }
2594
+ return true;
2595
+ });
2596
+ node.properties.dataType = "taskItem";
2597
+ node.properties.dataChecked = String(checked);
2598
+ node.properties.className = void 0;
2599
+ });
2600
+ (0, import_unist_util_visit.visit)(tree, "element", (node) => {
2601
+ if (node.tagName !== "ul") return;
2602
+ const hasTaskItem = node.children.some(
2603
+ (child) => isElement(child) && child.properties.dataType === "taskItem"
2604
+ );
2605
+ if (hasTaskItem) {
2606
+ node.properties.dataType = "taskList";
2607
+ node.properties.className = void 0;
2608
+ }
2609
+ });
2610
+ };
2611
+ }
2612
+ function tiptapTaskListsToGfm() {
2613
+ return (tree) => {
2614
+ (0, import_unist_util_visit.visit)(tree, "element", (node) => {
2615
+ if (node.tagName !== "li" || node.properties.dataType !== "taskItem") {
2616
+ return;
2617
+ }
2618
+ const checked = node.properties.dataChecked === "true";
2619
+ const content = [];
2620
+ for (const child of node.children) {
2621
+ if (isElement(child) && child.tagName === "label") continue;
2622
+ if (isElement(child) && child.tagName === "div") {
2623
+ content.push(...child.children);
2624
+ } else {
2625
+ content.push(child);
2626
+ }
2627
+ }
2628
+ const checkbox = {
2629
+ type: "element",
2630
+ tagName: "input",
2631
+ properties: { type: "checkbox", checked, disabled: true },
2632
+ children: []
2633
+ };
2634
+ node.children = [checkbox, ...content];
2635
+ });
2636
+ };
2637
+ }
2638
+ function tightenListItems() {
2639
+ return (tree) => {
2640
+ (0, import_unist_util_visit.visit)(tree, "element", (node) => {
2641
+ if (node.tagName !== "li") return;
2642
+ const paragraphs = node.children.filter(
2643
+ (child) => isElement(child) && child.tagName === "p"
2644
+ );
2645
+ if (paragraphs.length !== 1) return;
2646
+ node.children = node.children.flatMap(
2647
+ (child) => isElement(child) && child.tagName === "p" ? child.children : [child]
2648
+ );
2649
+ });
2650
+ };
2651
+ }
2652
+ function markdownToEditorHtml(markdown) {
2653
+ const file = (0, import_unified.unified)().use(import_remark_parse.default).use(import_remark_gfm.default).use(embedRawHtml).use(import_remark_rehype.default).use(taskListsToTiptap).use(import_rehype_stringify.default).processSync(markdown);
2654
+ return String(file);
2655
+ }
2656
+ function editorHtmlToMarkdown(html) {
2657
+ const file = (0, import_unified.unified)().use(import_rehype_parse.default, { fragment: true }).use(tiptapTaskListsToGfm).use(tightenListItems).use(import_rehype_remark.default, {
2658
+ handlers: {
2659
+ div(state, node) {
2660
+ const raw = node.properties.dataRawHtml;
2661
+ if (typeof raw === "string") {
2662
+ return { type: "html", value: decodeURIComponent(raw) };
2663
+ }
2664
+ return state.all(node);
2665
+ }
2666
+ }
2667
+ }).use(import_remark_gfm.default).use(import_remark_stringify.default, STRINGIFY_OPTIONS).processSync(html);
2668
+ return String(file);
2669
+ }
2670
+ function markdownToHtml(markdown, options) {
2671
+ const processor = (0, import_unified.unified)().use(import_remark_parse.default).use(import_remark_gfm.default).use(import_remark_rehype.default, { allowDangerousHtml: true }).use(import_rehype_raw.default).use(import_rehype_highlight.default, {
2672
+ languages: HIGHLIGHT_LANGUAGES,
2673
+ ignoreMissing: true
2674
+ });
2675
+ const withSanitize = options.sanitize ? processor.use(import_rehype_sanitize.default, sanitizeSchemaWithHighlight) : processor;
2676
+ const file = withSanitize.use(import_rehype_stringify.default).processSync(markdown);
2677
+ return String(file);
2678
+ }
2679
+ function sanitizeHtmlFragment(html) {
2680
+ const file = (0, import_unified.unified)().use(import_rehype_parse.default, { fragment: true }).use(import_rehype_sanitize.default).use(import_rehype_stringify.default).processSync(html);
2681
+ return String(file);
2682
+ }
2683
+
2684
+ // src/components/MarkdownEditor/markdown/tiptapMarkdownBridge.ts
2685
+ var lowlight = (0, import_lowlight.createLowlight)();
2686
+ lowlight.register({ json, sql, typescript, javascript: javascript2, java });
2687
+ var HtmlBlock = import_core.Node.create({
2688
+ name: "htmlBlock",
2689
+ group: "block",
2690
+ atom: true,
2691
+ addOptions() {
2692
+ return { sanitize: true };
2693
+ },
2694
+ addAttributes() {
2695
+ return { content: { default: "" } };
2696
+ },
2697
+ parseHTML() {
2698
+ return [
2699
+ {
2700
+ tag: "div[data-raw-html]",
2701
+ getAttrs: (element) => {
2702
+ const raw = element.getAttribute("data-raw-html");
2703
+ return raw === null ? false : { content: decodeURIComponent(raw) };
2704
+ }
2705
+ }
2706
+ ];
2707
+ },
2708
+ renderHTML({ node }) {
2709
+ const content = node.attrs["content"];
2710
+ return ["div", { "data-raw-html": encodeURIComponent(content) }];
2711
+ },
2712
+ addNodeView() {
2713
+ return ({ node }) => {
2714
+ const dom = document.createElement("div");
2715
+ dom.setAttribute("data-html-block", "");
2716
+ const raw = node.attrs["content"];
2717
+ dom.innerHTML = this.options.sanitize ? sanitizeHtmlFragment(raw) : raw;
2718
+ return { dom };
2719
+ };
2720
+ }
2721
+ });
2722
+ function createEditorExtensions(options) {
2723
+ return [
2724
+ import_starter_kit.default.configure({ codeBlock: false }),
2725
+ import_extension_code_block_lowlight.default.configure({ lowlight }),
2726
+ import_extension_table.default.configure({ resizable: false }),
2727
+ import_extension_table_row.default,
2728
+ import_extension_table_header.default,
2729
+ import_extension_table_cell.default,
2730
+ import_extension_task_list.default,
2731
+ import_extension_task_item.default.configure({ nested: true }),
2732
+ import_extension_link.default.configure({ openOnClick: false }),
2733
+ import_extension_image.default,
2734
+ HtmlBlock.configure({ sanitize: options.sanitizeEmbeddedHtml })
2735
+ ];
2736
+ }
2737
+ function markdownToEditorContent(markdown) {
2738
+ return markdownToEditorHtml(markdown);
2739
+ }
2740
+ function editorToMarkdown(editor) {
2741
+ return editorHtmlToMarkdown(editor.getHTML());
2742
+ }
2743
+
2744
+ // src/components/MarkdownEditor/views/RenderedView.tsx
2745
+ var import_react = require("@tiptap/react");
2746
+ var import_jsx_runtime = require("react/jsx-runtime");
2747
+ function RenderedView({ editor }) {
2748
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.EditorContent, { editor });
2749
+ }
2750
+
2751
+ // src/components/MarkdownEditor/MarkdownEditor.module.css
2752
+ var MarkdownEditor_default = {};
2753
+
2754
+ // src/components/MarkdownEditor/views/MarkdownSourceView.tsx
2755
+ var import_jsx_runtime2 = require("react/jsx-runtime");
2756
+ function MarkdownSourceView({
2757
+ value,
2758
+ onChange,
2759
+ readOnly = false
2760
+ }) {
2761
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
2762
+ "textarea",
2763
+ {
2764
+ className: MarkdownEditor_default["source"],
2765
+ "aria-label": "C\xF3digo fuente Markdown",
2766
+ spellCheck: false,
2767
+ value,
2768
+ readOnly,
2769
+ onChange: (event) => onChange(event.target.value)
2770
+ }
2771
+ );
2772
+ }
2773
+
2774
+ // src/components/MarkdownEditor/Toolbar/Toolbar.tsx
2775
+ var import_react7 = require("react");
2776
+
2777
+ // src/components/MarkdownEditor/Toolbar/buttons/ToolbarButton.tsx
2778
+ var import_jsx_runtime3 = require("react/jsx-runtime");
2779
+ function ToolbarButton({
2780
+ label,
2781
+ pressed,
2782
+ className,
2783
+ children,
2784
+ ...rest
2785
+ }) {
2786
+ const buttonClass = className === void 0 ? MarkdownEditor_default["button"] : `${MarkdownEditor_default["button"]} ${className}`;
2787
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
2788
+ "button",
2789
+ {
2790
+ type: "button",
2791
+ className: buttonClass,
2792
+ "aria-label": label,
2793
+ title: label,
2794
+ ...pressed !== void 0 ? { "aria-pressed": pressed } : {},
2795
+ ...rest,
2796
+ children
2797
+ }
2798
+ );
2799
+ }
2800
+
2801
+ // src/components/MarkdownEditor/Toolbar/buttons/InsertDialogs.tsx
2802
+ var import_react2 = require("react");
2803
+
2804
+ // src/components/MarkdownEditor/markdown/links.ts
2805
+ function ensureProtocol(url) {
2806
+ return url.includes("://") ? url : `http://${url}`;
2807
+ }
2808
+
2809
+ // src/components/MarkdownEditor/Toolbar/buttons/InsertDialogs.tsx
2810
+ var import_jsx_runtime4 = require("react/jsx-runtime");
2811
+ function DialogShell({ title, onSubmit, onClose, children }) {
2812
+ const ref = (0, import_react2.useRef)(null);
2813
+ (0, import_react2.useEffect)(() => {
2814
+ const first = ref.current?.querySelector("input, textarea");
2815
+ first?.focus();
2816
+ }, []);
2817
+ const handleSubmit = (event) => {
2818
+ event.preventDefault();
2819
+ onSubmit();
2820
+ };
2821
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
2822
+ "form",
2823
+ {
2824
+ ref,
2825
+ className: MarkdownEditor_default["dialog"],
2826
+ role: "dialog",
2827
+ "aria-label": title,
2828
+ onSubmit: handleSubmit,
2829
+ onKeyDown: (event) => {
2830
+ if (event.key === "Escape") {
2831
+ event.stopPropagation();
2832
+ onClose();
2833
+ }
2834
+ },
2835
+ children: [
2836
+ children,
2837
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: MarkdownEditor_default["dialogActions"], children: [
2838
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
2839
+ "button",
2840
+ {
2841
+ type: "button",
2842
+ className: `${MarkdownEditor_default["button"]} ${MarkdownEditor_default["textButton"]}`,
2843
+ onClick: onClose,
2844
+ children: "Cancelar"
2845
+ }
2846
+ ),
2847
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
2848
+ "button",
2849
+ {
2850
+ type: "submit",
2851
+ className: `${MarkdownEditor_default["button"]} ${MarkdownEditor_default["textButton"]}`,
2852
+ children: "Insertar"
2853
+ }
2854
+ )
2855
+ ] })
2856
+ ]
2857
+ }
2858
+ );
2859
+ }
2860
+ function Field({ label, children }) {
2861
+ const id = (0, import_react2.useId)();
2862
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: MarkdownEditor_default["dialogField"], children: [
2863
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("label", { htmlFor: id, children: label }),
2864
+ children(id)
2865
+ ] });
2866
+ }
2867
+ function InsertDialog({ kind, editor, onClose }) {
2868
+ const [url, setUrl] = (0, import_react2.useState)("");
2869
+ const [text, setText] = (0, import_react2.useState)("");
2870
+ const [html, setHtml] = (0, import_react2.useState)("");
2871
+ const [hasSelectionForLink] = (0, import_react2.useState)(
2872
+ () => kind === "link" && !editor.state.selection.empty
2873
+ );
2874
+ const submit = () => {
2875
+ const chain = editor.chain().focus();
2876
+ if (kind === "image" && url) {
2877
+ chain.setImage({ src: url, alt: text }).run();
2878
+ } else if (kind === "link" && url) {
2879
+ const href = ensureProtocol(url);
2880
+ if (hasSelectionForLink) {
2881
+ chain.extendMarkRange("link").setLink({ href }).run();
2882
+ } else if (text) {
2883
+ chain.insertContent({
2884
+ type: "text",
2885
+ text,
2886
+ marks: [{ type: "link", attrs: { href } }]
2887
+ }).run();
2888
+ }
2889
+ } else if (kind === "html" && html) {
2890
+ chain.insertContent({ type: "htmlBlock", attrs: { content: html } }).run();
2891
+ }
2892
+ onClose();
2893
+ };
2894
+ if (kind === "html") {
2895
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
2896
+ DialogShell,
2897
+ {
2898
+ title: "Insertar HTML embebido",
2899
+ onSubmit: submit,
2900
+ onClose,
2901
+ children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Field, { label: "C\xF3digo HTML", children: (id) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
2902
+ "textarea",
2903
+ {
2904
+ id,
2905
+ rows: 4,
2906
+ value: html,
2907
+ onChange: (e) => setHtml(e.target.value)
2908
+ }
2909
+ ) })
2910
+ }
2911
+ );
2912
+ }
2913
+ const isImage = kind === "image";
2914
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
2915
+ DialogShell,
2916
+ {
2917
+ title: isImage ? "Insertar imagen" : "Insertar enlace",
2918
+ onSubmit: submit,
2919
+ onClose,
2920
+ children: [
2921
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Field, { label: isImage ? "URL de la imagen" : "URL del enlace", children: (id) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
2922
+ "input",
2923
+ {
2924
+ id,
2925
+ type: isImage ? "url" : "text",
2926
+ required: true,
2927
+ value: url,
2928
+ onChange: (e) => setUrl(e.target.value)
2929
+ }
2930
+ ) }),
2931
+ !(kind === "link" && hasSelectionForLink) && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Field, { label: isImage ? "Texto alternativo" : "Texto del enlace", children: (id) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
2932
+ "input",
2933
+ {
2934
+ id,
2935
+ type: "text",
2936
+ value: text,
2937
+ onChange: (e) => setText(e.target.value)
2938
+ }
2939
+ ) })
2940
+ ]
2941
+ }
2942
+ );
2943
+ }
2944
+
2945
+ // src/components/MarkdownEditor/Toolbar/buttons/TableSizePicker.tsx
2946
+ var import_react3 = require("react");
2947
+ var import_jsx_runtime5 = require("react/jsx-runtime");
2948
+ function TableSizePicker({
2949
+ maxCols = 10,
2950
+ maxRows = 10,
2951
+ onSelect,
2952
+ onClose
2953
+ }) {
2954
+ const [size, setSize] = (0, import_react3.useState)(null);
2955
+ const gridRef = (0, import_react3.useRef)(null);
2956
+ (0, import_react3.useEffect)(() => {
2957
+ gridRef.current?.focus();
2958
+ }, []);
2959
+ const clamp = (value, max) => Math.min(Math.max(value, 1), max);
2960
+ const handleKeyDown = (event) => {
2961
+ if (event.key === "Escape") {
2962
+ event.stopPropagation();
2963
+ onClose();
2964
+ return;
2965
+ }
2966
+ if (event.key === "Enter" || event.key === " ") {
2967
+ event.preventDefault();
2968
+ if (size !== null) onSelect(size);
2969
+ return;
2970
+ }
2971
+ const deltas = {
2972
+ ArrowRight: [1, 0],
2973
+ ArrowLeft: [-1, 0],
2974
+ ArrowDown: [0, 1],
2975
+ ArrowUp: [0, -1]
2976
+ };
2977
+ const delta = deltas[event.key];
2978
+ if (delta === void 0) return;
2979
+ event.preventDefault();
2980
+ const current = size ?? { cols: 0, rows: 0 };
2981
+ setSize({
2982
+ cols: clamp(current.cols + delta[0], maxCols),
2983
+ rows: clamp(current.rows + delta[1], maxRows)
2984
+ });
2985
+ };
2986
+ const label = size === null ? "Selecciona el tama\xF1o" : `${size.cols} \xD7 ${size.rows}`;
2987
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
2988
+ "div",
2989
+ {
2990
+ className: `${MarkdownEditor_default["dialog"]} ${MarkdownEditor_default["tablePicker"]}`,
2991
+ role: "dialog",
2992
+ "aria-label": "Insertar tabla",
2993
+ children: [
2994
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: MarkdownEditor_default["tablePickerLabel"], "aria-live": "polite", children: label }),
2995
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
2996
+ "div",
2997
+ {
2998
+ ref: gridRef,
2999
+ className: MarkdownEditor_default["tablePickerGrid"],
3000
+ style: { gridTemplateColumns: `repeat(${maxCols}, 16px)` },
3001
+ tabIndex: 0,
3002
+ role: "group",
3003
+ "aria-label": "Tama\xF1o de la tabla (columnas \xD7 filas)",
3004
+ onKeyDown: handleKeyDown,
3005
+ children: Array.from(
3006
+ { length: maxRows },
3007
+ (_, rowIndex) => Array.from({ length: maxCols }, (_2, colIndex) => {
3008
+ const cell = {
3009
+ cols: colIndex + 1,
3010
+ rows: rowIndex + 1
3011
+ };
3012
+ const selected = size !== null && cell.cols <= size.cols && cell.rows <= size.rows;
3013
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
3014
+ "div",
3015
+ {
3016
+ className: MarkdownEditor_default["tablePickerCell"],
3017
+ "data-cell": `${cell.cols}x${cell.rows}`,
3018
+ "data-selected": selected ? "true" : "false",
3019
+ "aria-hidden": "true",
3020
+ onMouseEnter: () => setSize(cell),
3021
+ onClick: () => onSelect(cell)
3022
+ },
3023
+ `${cell.cols}x${cell.rows}`
3024
+ );
3025
+ })
3026
+ )
3027
+ }
3028
+ )
3029
+ ]
3030
+ }
3031
+ );
3032
+ }
3033
+
3034
+ // src/components/MarkdownEditor/Toolbar/buttons/CodeLanguagePicker.tsx
3035
+ var import_react4 = require("react");
3036
+ var import_jsx_runtime6 = require("react/jsx-runtime");
3037
+ var CODE_LANGUAGES = [
3038
+ { value: "json", label: "JSON" },
3039
+ { value: "sql", label: "SQL" },
3040
+ { value: "typescript", label: "TypeScript" },
3041
+ { value: "javascript", label: "JavaScript" },
3042
+ { value: "java", label: "Java" }
3043
+ ];
3044
+ function CodeLanguagePicker({
3045
+ currentLanguage,
3046
+ onSelect,
3047
+ onClose
3048
+ }) {
3049
+ const isKnown = CODE_LANGUAGES.some(
3050
+ (lang) => lang.value === currentLanguage
3051
+ );
3052
+ const [choice, setChoice] = (0, import_react4.useState)(
3053
+ isKnown ? currentLanguage : "other"
3054
+ );
3055
+ const [otherValue, setOtherValue] = (0, import_react4.useState)(
3056
+ !isKnown && currentLanguage ? currentLanguage : ""
3057
+ );
3058
+ const formRef = (0, import_react4.useRef)(null);
3059
+ const otherFieldId = (0, import_react4.useId)();
3060
+ (0, import_react4.useEffect)(() => {
3061
+ formRef.current?.querySelector("select")?.focus();
3062
+ }, []);
3063
+ const submit = () => {
3064
+ const language = choice === "other" ? otherValue.trim() : choice;
3065
+ if (language) onSelect(language);
3066
+ };
3067
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
3068
+ "form",
3069
+ {
3070
+ ref: formRef,
3071
+ className: MarkdownEditor_default["dialog"],
3072
+ role: "dialog",
3073
+ "aria-label": "Lenguaje del bloque de c\xF3digo",
3074
+ onSubmit: (event) => {
3075
+ event.preventDefault();
3076
+ submit();
3077
+ },
3078
+ onKeyDown: (event) => {
3079
+ if (event.key === "Escape") {
3080
+ event.stopPropagation();
3081
+ onClose();
3082
+ }
3083
+ },
3084
+ children: [
3085
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: MarkdownEditor_default["dialogField"], children: [
3086
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("label", { htmlFor: "mdw-code-language", children: "Lenguaje" }),
3087
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
3088
+ "select",
3089
+ {
3090
+ id: "mdw-code-language",
3091
+ value: choice,
3092
+ onChange: (event) => setChoice(event.target.value),
3093
+ children: [
3094
+ CODE_LANGUAGES.map((lang) => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("option", { value: lang.value, children: lang.label }, lang.value)),
3095
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("option", { value: "other", children: "Otro\u2026" })
3096
+ ]
3097
+ }
3098
+ )
3099
+ ] }),
3100
+ choice === "other" && /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: MarkdownEditor_default["dialogField"], children: [
3101
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("label", { htmlFor: otherFieldId, children: "Especificar lenguaje" }),
3102
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
3103
+ "input",
3104
+ {
3105
+ id: otherFieldId,
3106
+ type: "text",
3107
+ value: otherValue,
3108
+ onChange: (event) => setOtherValue(event.target.value)
3109
+ }
3110
+ )
3111
+ ] }),
3112
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: MarkdownEditor_default["dialogActions"], children: [
3113
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
3114
+ "button",
3115
+ {
3116
+ type: "button",
3117
+ className: `${MarkdownEditor_default["button"]} ${MarkdownEditor_default["textButton"]}`,
3118
+ onClick: onClose,
3119
+ children: "Cancelar"
3120
+ }
3121
+ ),
3122
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
3123
+ "button",
3124
+ {
3125
+ type: "submit",
3126
+ className: `${MarkdownEditor_default["button"]} ${MarkdownEditor_default["textButton"]}`,
3127
+ children: "Aplicar"
3128
+ }
3129
+ )
3130
+ ] })
3131
+ ]
3132
+ }
3133
+ );
3134
+ }
3135
+
3136
+ // src/components/MarkdownEditor/Toolbar/buttons/FloatingPanel.tsx
3137
+ var import_react5 = require("react");
3138
+ var import_react_dom = require("react-dom");
3139
+ var import_jsx_runtime7 = require("react/jsx-runtime");
3140
+ function FloatingPanel({
3141
+ anchor,
3142
+ align = "start",
3143
+ autoFocus = false,
3144
+ children
3145
+ }) {
3146
+ const panelRef = (0, import_react5.useRef)(null);
3147
+ const [style, setStyle] = (0, import_react5.useState)(null);
3148
+ (0, import_react5.useLayoutEffect)(() => {
3149
+ if (!anchor) return;
3150
+ const rect = anchor.getBoundingClientRect();
3151
+ if (align === "end") {
3152
+ setStyle({
3153
+ top: rect.bottom,
3154
+ right: Math.max(0, window.innerWidth - rect.right)
3155
+ });
3156
+ } else {
3157
+ setStyle({ top: rect.bottom, left: rect.left });
3158
+ }
3159
+ }, [anchor, align]);
3160
+ (0, import_react5.useLayoutEffect)(() => {
3161
+ if (style === null || !autoFocus) return;
3162
+ panelRef.current?.querySelector(
3163
+ 'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])'
3164
+ )?.focus();
3165
+ }, [style !== null]);
3166
+ if (style === null) return null;
3167
+ return (0, import_react_dom.createPortal)(
3168
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
3169
+ "div",
3170
+ {
3171
+ ref: panelRef,
3172
+ className: MarkdownEditor_default["root"],
3173
+ style: {
3174
+ position: "fixed",
3175
+ top: style.top,
3176
+ left: style.left,
3177
+ right: style.right,
3178
+ zIndex: 1e3,
3179
+ // El wrapper solo restablece las custom properties/tipografía del
3180
+ // componente para el contenido portado; no debe verse como una caja.
3181
+ border: "none",
3182
+ overflow: "visible",
3183
+ background: "transparent",
3184
+ width: "auto",
3185
+ height: "auto"
3186
+ },
3187
+ children
3188
+ }
3189
+ ),
3190
+ document.body
3191
+ );
3192
+ }
3193
+
3194
+ // src/components/MarkdownEditor/Toolbar/buttons/ExportMenu.tsx
3195
+ var import_react6 = require("react");
3196
+
3197
+ // src/components/MarkdownEditor/Toolbar/buttons/icons.tsx
3198
+ var import_jsx_runtime8 = require("react/jsx-runtime");
3199
+ var base = { viewBox: "0 0 24 24", "aria-hidden": true };
3200
+ function IconCode(props) {
3201
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("svg", { ...base, ...props, children: [
3202
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("path", { d: "M9 7L4 12L9 17" }),
3203
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("path", { d: "M15 7L20 12L15 17" }),
3204
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("path", { d: "M14 4L10 20" })
3205
+ ] });
3206
+ }
3207
+ function IconCodeBlock(props) {
3208
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("svg", { ...base, ...props, children: [
3209
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("path", { d: "M8 6L3 12L8 18" }),
3210
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("path", { d: "M16 6L21 12L16 18" })
3211
+ ] });
3212
+ }
3213
+ function IconBullets(props) {
3214
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("svg", { ...base, ...props, children: [
3215
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("circle", { cx: "4", cy: "6", r: "1" }),
3216
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("circle", { cx: "4", cy: "12", r: "1" }),
3217
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("circle", { cx: "4", cy: "18", r: "1" }),
3218
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("path", { d: "M9 6H21" }),
3219
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("path", { d: "M9 12H21" }),
3220
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("path", { d: "M9 18H21" })
3221
+ ] });
3222
+ }
3223
+ function IconNumbered(props) {
3224
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("svg", { ...base, ...props, children: [
3225
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("path", { d: "M4 5H5V9" }),
3226
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("path", { d: "M3 9H6" }),
3227
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("path", { d: "M3 13H6" }),
3228
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("path", { d: "M3 17C3 15 6 15 6 17C6 19 3 19 3 19H6" }),
3229
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("path", { d: "M10 6H21" }),
3230
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("path", { d: "M10 12H21" }),
3231
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("path", { d: "M10 18H21" })
3232
+ ] });
3233
+ }
3234
+ function IconChecklist(props) {
3235
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("svg", { ...base, ...props, children: [
3236
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("rect", { x: "3", y: "3", width: "6", height: "6" }),
3237
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("path", { d: "M4 6L6 8L9 4" }),
3238
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("path", { d: "M12 6H21" }),
3239
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("rect", { x: "3", y: "14", width: "6", height: "6" }),
3240
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("path", { d: "M12 17H21" })
3241
+ ] });
3242
+ }
3243
+ function IconIndent(props) {
3244
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("svg", { ...base, ...props, children: [
3245
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("path", { d: "M3 6H21" }),
3246
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("path", { d: "M11 12H21" }),
3247
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("path", { d: "M3 18H21" }),
3248
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("path", { d: "M3 9.5L6 12L3 14.5" })
3249
+ ] });
3250
+ }
3251
+ function IconOutdent(props) {
3252
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("svg", { ...base, ...props, children: [
3253
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("path", { d: "M3 6H21" }),
3254
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("path", { d: "M11 12H21" }),
3255
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("path", { d: "M3 18H21" }),
3256
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("path", { d: "M6 9.5L3 12L6 14.5" })
3257
+ ] });
3258
+ }
3259
+ function IconQuote(props) {
3260
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("svg", { ...base, ...props, children: [
3261
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("path", { d: "M7 8H4V12H8V8C8 5 6 4 4 4" }),
3262
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("path", { d: "M17 8H14V12H18V8C18 5 16 4 14 4" })
3263
+ ] });
3264
+ }
3265
+ function IconTable(props) {
3266
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("svg", { ...base, ...props, children: [
3267
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("rect", { x: "3", y: "4", width: "18", height: "16" }),
3268
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("path", { d: "M3 10H21" }),
3269
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("path", { d: "M3 15H21" }),
3270
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("path", { d: "M9 4V20" }),
3271
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("path", { d: "M15 4V20" })
3272
+ ] });
3273
+ }
3274
+ function IconLink(props) {
3275
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("svg", { ...base, ...props, children: [
3276
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("path", { d: "M10 13C11.5 14.5 14 14.5 15.5 13L18 10.5C20 8.5 20 5.5 18 3.5C16 1.5 13 1.5 11 3.5L9.5 5" }),
3277
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("path", { d: "M14 11C12.5 9.5 10 9.5 8.5 11L6 13.5C4 15.5 4 18.5 6 20.5C8 22.5 11 22.5 13 20.5L14.5 19" })
3278
+ ] });
3279
+ }
3280
+ function IconImage(props) {
3281
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("svg", { ...base, ...props, children: [
3282
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("rect", { x: "3", y: "4", width: "18", height: "16" }),
3283
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("circle", { cx: "8", cy: "9", r: "2" }),
3284
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("path", { d: "M3 17L8 12L12 16L15 13L21 19" })
3285
+ ] });
3286
+ }
3287
+ function IconHr(props) {
3288
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("svg", { ...base, ...props, children: [
3289
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("path", { d: "M3 12H21" }),
3290
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("path", { d: "M6 6H18", opacity: "0.35" }),
3291
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("path", { d: "M6 18H18", opacity: "0.35" })
3292
+ ] });
3293
+ }
3294
+ function IconDownload(props) {
3295
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("svg", { ...base, ...props, children: [
3296
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("path", { d: "M12 3V15" }),
3297
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("path", { d: "M7 10L12 15L17 10" }),
3298
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("path", { d: "M4 19H20" })
3299
+ ] });
3300
+ }
3301
+
3302
+ // src/components/MarkdownEditor/Toolbar/buttons/ExportMenu.tsx
3303
+ var import_jsx_runtime9 = require("react/jsx-runtime");
3304
+ function ExportMenu({ source, sanitize }) {
3305
+ const [open, setOpen] = (0, import_react6.useState)(false);
3306
+ const buttonRef = (0, import_react6.useRef)(null);
3307
+ const close = () => {
3308
+ setOpen(false);
3309
+ buttonRef.current?.focus();
3310
+ };
3311
+ const copy = (content) => {
3312
+ void navigator.clipboard.writeText(content);
3313
+ close();
3314
+ };
3315
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_jsx_runtime9.Fragment, { children: [
3316
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
3317
+ "button",
3318
+ {
3319
+ ref: buttonRef,
3320
+ type: "button",
3321
+ className: MarkdownEditor_default["button"],
3322
+ "aria-label": "Export",
3323
+ title: "Export",
3324
+ "aria-haspopup": "menu",
3325
+ "aria-expanded": open,
3326
+ onClick: () => setOpen((value) => !value),
3327
+ children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(IconDownload, {})
3328
+ }
3329
+ ),
3330
+ open && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(FloatingPanel, { anchor: buttonRef.current, align: "end", autoFocus: true, children: /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
3331
+ "div",
3332
+ {
3333
+ role: "menu",
3334
+ "aria-label": "Exportar contenido",
3335
+ className: MarkdownEditor_default["menu"],
3336
+ onKeyDown: (event) => {
3337
+ if (event.key === "Escape") {
3338
+ event.stopPropagation();
3339
+ close();
3340
+ }
3341
+ },
3342
+ children: [
3343
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
3344
+ "button",
3345
+ {
3346
+ type: "button",
3347
+ role: "menuitem",
3348
+ className: MarkdownEditor_default["menuItem"],
3349
+ onClick: () => copy(source),
3350
+ children: "Copiar como Markdown"
3351
+ }
3352
+ ),
3353
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
3354
+ "button",
3355
+ {
3356
+ type: "button",
3357
+ role: "menuitem",
3358
+ className: MarkdownEditor_default["menuItem"],
3359
+ onClick: () => copy(markdownToHtml(source, { sanitize })),
3360
+ children: "Copiar como HTML"
3361
+ }
3362
+ )
3363
+ ]
3364
+ }
3365
+ ) })
3366
+ ] });
3367
+ }
3368
+
3369
+ // src/components/MarkdownEditor/Toolbar/buttons/Separator.tsx
3370
+ var import_jsx_runtime10 = require("react/jsx-runtime");
3371
+ function Separator() {
3372
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { className: MarkdownEditor_default["separator"], "aria-hidden": "true" });
3373
+ }
3374
+
3375
+ // src/components/MarkdownEditor/Toolbar/Toolbar.tsx
3376
+ var import_jsx_runtime11 = require("react/jsx-runtime");
3377
+ var HEADING_LEVELS = [1, 2, 3, 4, 5, 6];
3378
+ function Toolbar({
3379
+ editor,
3380
+ viewMode,
3381
+ onToggleView,
3382
+ source,
3383
+ sanitizeEmbeddedHtml,
3384
+ onlyView = false
3385
+ }) {
3386
+ const [, forceUpdate] = (0, import_react7.useReducer)((count) => count + 1, 0);
3387
+ const [openDialog, setOpenDialog] = (0, import_react7.useState)(null);
3388
+ const [anchor, setAnchor] = (0, import_react7.useState)(null);
3389
+ const openDialogAt = (kind, event) => {
3390
+ setAnchor(event.currentTarget);
3391
+ setOpenDialog(kind);
3392
+ };
3393
+ (0, import_react7.useEffect)(() => {
3394
+ if (!editor) return;
3395
+ editor.on("transaction", forceUpdate);
3396
+ return () => {
3397
+ editor.off("transaction", forceUpdate);
3398
+ };
3399
+ }, [editor]);
3400
+ if (onlyView) {
3401
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(
3402
+ "div",
3403
+ {
3404
+ role: "toolbar",
3405
+ "aria-label": "Barra de herramientas",
3406
+ className: MarkdownEditor_default["toolbar"],
3407
+ children: [
3408
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("span", { className: MarkdownEditor_default["readOnlyNotice"], children: "Edici\xF3n desactivada" }),
3409
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { className: MarkdownEditor_default["spacer"], children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(ExportMenu, { source, sanitize: sanitizeEmbeddedHtml }) })
3410
+ ]
3411
+ }
3412
+ );
3413
+ }
3414
+ const canFormat = viewMode === "wysiwyg" && editor !== null;
3415
+ const activeHeading = canFormat ? HEADING_LEVELS.find(
3416
+ (level) => editor.isActive("heading", { level })
3417
+ ) ?? null : null;
3418
+ const listItemType = canFormat && editor.isActive("taskItem") ? "taskItem" : "listItem";
3419
+ const closeDialog = () => setOpenDialog(null);
3420
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(
3421
+ "div",
3422
+ {
3423
+ role: "toolbar",
3424
+ "aria-label": "Barra de herramientas",
3425
+ className: MarkdownEditor_default["toolbar"],
3426
+ children: [
3427
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
3428
+ ToolbarButton,
3429
+ {
3430
+ label: "Ver c\xF3digo Markdown",
3431
+ pressed: viewMode === "markdown",
3432
+ onClick: onToggleView,
3433
+ children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(IconCode, {})
3434
+ }
3435
+ ),
3436
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(
3437
+ "select",
3438
+ {
3439
+ className: MarkdownEditor_default["headingSelect"],
3440
+ "aria-label": "Nivel de encabezado",
3441
+ disabled: !canFormat,
3442
+ value: activeHeading === null ? "p" : `h${activeHeading}`,
3443
+ onChange: (event) => {
3444
+ if (!editor) return;
3445
+ const value = event.target.value;
3446
+ if (value === "p") {
3447
+ editor.chain().focus().setParagraph().run();
3448
+ } else {
3449
+ const level = Number(value.slice(1));
3450
+ editor.chain().focus().setHeading({ level }).run();
3451
+ }
3452
+ },
3453
+ children: [
3454
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("option", { value: "p", children: "P\xE1rrafo" }),
3455
+ HEADING_LEVELS.map((level) => /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("option", { value: `h${level}`, children: [
3456
+ "Encabezado ",
3457
+ level
3458
+ ] }, level))
3459
+ ]
3460
+ }
3461
+ ),
3462
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
3463
+ ToolbarButton,
3464
+ {
3465
+ label: "Negrita",
3466
+ className: MarkdownEditor_default["boldGlyph"],
3467
+ disabled: !canFormat,
3468
+ pressed: canFormat && editor.isActive("bold"),
3469
+ onClick: () => editor?.chain().focus().toggleBold().run(),
3470
+ children: "B"
3471
+ }
3472
+ ),
3473
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
3474
+ ToolbarButton,
3475
+ {
3476
+ label: "Cursiva",
3477
+ className: MarkdownEditor_default["italicGlyph"],
3478
+ disabled: !canFormat,
3479
+ pressed: canFormat && editor.isActive("italic"),
3480
+ onClick: () => editor?.chain().focus().toggleItalic().run(),
3481
+ children: "i"
3482
+ }
3483
+ ),
3484
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
3485
+ ToolbarButton,
3486
+ {
3487
+ label: "Tachado",
3488
+ className: MarkdownEditor_default["strikeGlyph"],
3489
+ disabled: !canFormat,
3490
+ pressed: canFormat && editor.isActive("strike"),
3491
+ onClick: () => editor?.chain().focus().toggleStrike().run(),
3492
+ children: "S"
3493
+ }
3494
+ ),
3495
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(Separator, {}),
3496
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
3497
+ ToolbarButton,
3498
+ {
3499
+ label: "Lista con vi\xF1etas",
3500
+ disabled: !canFormat,
3501
+ pressed: canFormat && editor.isActive("bulletList"),
3502
+ onClick: () => editor?.chain().focus().toggleBulletList().run(),
3503
+ children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(IconBullets, {})
3504
+ }
3505
+ ),
3506
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
3507
+ ToolbarButton,
3508
+ {
3509
+ label: "Lista ordenada",
3510
+ disabled: !canFormat,
3511
+ pressed: canFormat && editor.isActive("orderedList"),
3512
+ onClick: () => editor?.chain().focus().toggleOrderedList().run(),
3513
+ children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(IconNumbered, {})
3514
+ }
3515
+ ),
3516
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
3517
+ ToolbarButton,
3518
+ {
3519
+ label: "Lista de tareas",
3520
+ disabled: !canFormat,
3521
+ pressed: canFormat && editor.isActive("taskList"),
3522
+ onClick: () => editor?.chain().focus().toggleTaskList().run(),
3523
+ children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(IconChecklist, {})
3524
+ }
3525
+ ),
3526
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
3527
+ ToolbarButton,
3528
+ {
3529
+ label: "Aumentar sangr\xEDa",
3530
+ disabled: !canFormat || !editor.can().sinkListItem(listItemType),
3531
+ onClick: () => editor?.chain().focus().sinkListItem(listItemType).run(),
3532
+ children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(IconIndent, {})
3533
+ }
3534
+ ),
3535
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
3536
+ ToolbarButton,
3537
+ {
3538
+ label: "Disminuir sangr\xEDa",
3539
+ disabled: !canFormat || !editor.can().liftListItem(listItemType),
3540
+ onClick: () => editor?.chain().focus().liftListItem(listItemType).run(),
3541
+ children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(IconOutdent, {})
3542
+ }
3543
+ ),
3544
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(Separator, {}),
3545
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
3546
+ ToolbarButton,
3547
+ {
3548
+ label: "Bloque de c\xF3digo",
3549
+ disabled: !canFormat,
3550
+ pressed: canFormat && editor.isActive("codeBlock"),
3551
+ onClick: (event) => openDialogAt("codeLanguage", event),
3552
+ children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(IconCodeBlock, {})
3553
+ }
3554
+ ),
3555
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
3556
+ ToolbarButton,
3557
+ {
3558
+ label: "Cita",
3559
+ disabled: !canFormat,
3560
+ pressed: canFormat && editor.isActive("blockquote"),
3561
+ onClick: () => editor?.chain().focus().toggleBlockquote().run(),
3562
+ children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(IconQuote, {})
3563
+ }
3564
+ ),
3565
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
3566
+ ToolbarButton,
3567
+ {
3568
+ label: "Insertar tabla",
3569
+ disabled: !canFormat,
3570
+ onClick: (event) => openDialogAt("table", event),
3571
+ children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(IconTable, {})
3572
+ }
3573
+ ),
3574
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
3575
+ ToolbarButton,
3576
+ {
3577
+ label: "L\xEDnea horizontal",
3578
+ disabled: !canFormat,
3579
+ onClick: () => editor?.chain().focus().setHorizontalRule().run(),
3580
+ children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(IconHr, {})
3581
+ }
3582
+ ),
3583
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(Separator, {}),
3584
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
3585
+ ToolbarButton,
3586
+ {
3587
+ label: "Insertar enlace",
3588
+ disabled: !canFormat,
3589
+ pressed: canFormat && editor.isActive("link"),
3590
+ onClick: (event) => openDialogAt("link", event),
3591
+ children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(IconLink, {})
3592
+ }
3593
+ ),
3594
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
3595
+ ToolbarButton,
3596
+ {
3597
+ label: "Insertar imagen",
3598
+ disabled: !canFormat,
3599
+ onClick: (event) => openDialogAt("image", event),
3600
+ children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(IconImage, {})
3601
+ }
3602
+ ),
3603
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
3604
+ ToolbarButton,
3605
+ {
3606
+ label: "Insertar HTML",
3607
+ disabled: !canFormat,
3608
+ onClick: (event) => openDialogAt("html", event),
3609
+ children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("span", { className: MarkdownEditor_default["htmlIcon"], children: "HTML" })
3610
+ }
3611
+ ),
3612
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { className: MarkdownEditor_default["spacer"], children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(ExportMenu, { source, sanitize: sanitizeEmbeddedHtml }) }),
3613
+ openDialog === "table" && editor !== null && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(FloatingPanel, { anchor, children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
3614
+ TableSizePicker,
3615
+ {
3616
+ onSelect: ({ cols, rows }) => {
3617
+ editor.chain().focus().insertTable({ rows, cols, withHeaderRow: true }).run();
3618
+ closeDialog();
3619
+ },
3620
+ onClose: closeDialog
3621
+ }
3622
+ ) }),
3623
+ openDialog === "codeLanguage" && editor !== null && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(FloatingPanel, { anchor, children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
3624
+ CodeLanguagePicker,
3625
+ {
3626
+ currentLanguage: editor.getAttributes("codeBlock")["language"] ?? null,
3627
+ onSelect: (language) => {
3628
+ if (editor.isActive("codeBlock")) {
3629
+ editor.chain().focus().updateAttributes("codeBlock", { language }).run();
3630
+ } else {
3631
+ editor.chain().focus().toggleCodeBlock({ language }).run();
3632
+ }
3633
+ closeDialog();
3634
+ },
3635
+ onClose: closeDialog
3636
+ }
3637
+ ) }),
3638
+ openDialog !== null && openDialog !== "table" && openDialog !== "codeLanguage" && editor !== null && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(FloatingPanel, { anchor, children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
3639
+ InsertDialog,
3640
+ {
3641
+ kind: openDialog,
3642
+ editor,
3643
+ onClose: closeDialog
3644
+ }
3645
+ ) })
3646
+ ]
3647
+ }
3648
+ );
3649
+ }
3650
+
3651
+ // src/components/MarkdownEditor/Toolbar/buttons/LinkPopover.tsx
3652
+ var import_react8 = require("react");
3653
+ var import_jsx_runtime12 = require("react/jsx-runtime");
3654
+ function LinkPopover({
3655
+ url,
3656
+ onlyView,
3657
+ onNavigate,
3658
+ onCopy,
3659
+ onSave,
3660
+ onRemove,
3661
+ onClose
3662
+ }) {
3663
+ const [mode, setMode] = (0, import_react8.useState)("menu");
3664
+ const [inputValue, setInputValue] = (0, import_react8.useState)(url);
3665
+ const rootRef = (0, import_react8.useRef)(null);
3666
+ const inputId = (0, import_react8.useId)();
3667
+ (0, import_react8.useEffect)(() => {
3668
+ if (mode === "edit") {
3669
+ rootRef.current?.querySelector("input")?.focus();
3670
+ }
3671
+ }, [mode]);
3672
+ (0, import_react8.useEffect)(() => {
3673
+ const handlePointerDown = (event) => {
3674
+ if (rootRef.current !== null && !rootRef.current.contains(event.target)) {
3675
+ onClose();
3676
+ }
3677
+ };
3678
+ document.addEventListener("pointerdown", handlePointerDown);
3679
+ return () => {
3680
+ document.removeEventListener("pointerdown", handlePointerDown);
3681
+ };
3682
+ }, [onClose]);
3683
+ const handleKeyDown = (event) => {
3684
+ if (event.key === "Escape") {
3685
+ event.stopPropagation();
3686
+ onClose();
3687
+ }
3688
+ };
3689
+ const save = () => {
3690
+ if (!inputValue) return;
3691
+ onSave(ensureProtocol(inputValue));
3692
+ };
3693
+ if (mode === "edit") {
3694
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(
3695
+ "div",
3696
+ {
3697
+ ref: rootRef,
3698
+ className: MarkdownEditor_default["dialog"],
3699
+ role: "dialog",
3700
+ "aria-label": "Editar enlace",
3701
+ onKeyDown: handleKeyDown,
3702
+ children: [
3703
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { className: MarkdownEditor_default["dialogField"], children: [
3704
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("label", { htmlFor: inputId, children: "URL del enlace" }),
3705
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
3706
+ "input",
3707
+ {
3708
+ id: inputId,
3709
+ type: "text",
3710
+ value: inputValue,
3711
+ onChange: (event) => setInputValue(event.target.value)
3712
+ }
3713
+ )
3714
+ ] }),
3715
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
3716
+ "button",
3717
+ {
3718
+ type: "button",
3719
+ className: MarkdownEditor_default["dangerLink"],
3720
+ onClick: onRemove,
3721
+ children: "Eliminar link"
3722
+ }
3723
+ ),
3724
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { className: MarkdownEditor_default["dialogActions"], children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
3725
+ "button",
3726
+ {
3727
+ type: "button",
3728
+ className: `${MarkdownEditor_default["button"]} ${MarkdownEditor_default["textButton"]}`,
3729
+ onClick: save,
3730
+ children: "Guardar"
3731
+ }
3732
+ ) })
3733
+ ]
3734
+ }
3735
+ );
3736
+ }
3737
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(
3738
+ "div",
3739
+ {
3740
+ ref: rootRef,
3741
+ role: "menu",
3742
+ "aria-label": "Acciones del enlace",
3743
+ className: MarkdownEditor_default["menu"],
3744
+ onKeyDown: handleKeyDown,
3745
+ children: [
3746
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
3747
+ "button",
3748
+ {
3749
+ type: "button",
3750
+ role: "menuitem",
3751
+ className: MarkdownEditor_default["menuItem"],
3752
+ onClick: onNavigate,
3753
+ children: "Ir a la url"
3754
+ }
3755
+ ),
3756
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
3757
+ "button",
3758
+ {
3759
+ type: "button",
3760
+ role: "menuitem",
3761
+ className: MarkdownEditor_default["menuItem"],
3762
+ onClick: onCopy,
3763
+ children: "Copiar url"
3764
+ }
3765
+ ),
3766
+ !onlyView && /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_jsx_runtime12.Fragment, { children: [
3767
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("hr", { className: MarkdownEditor_default["menuSeparator"] }),
3768
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
3769
+ "button",
3770
+ {
3771
+ type: "button",
3772
+ role: "menuitem",
3773
+ className: MarkdownEditor_default["menuItem"],
3774
+ onClick: () => setMode("edit"),
3775
+ children: "Editar url"
3776
+ }
3777
+ )
3778
+ ] })
3779
+ ]
3780
+ }
3781
+ );
3782
+ }
3783
+
3784
+ // src/components/MarkdownEditor/MarkdownEditor.tsx
3785
+ var import_jsx_runtime13 = require("react/jsx-runtime");
3786
+ function toCssSize(value) {
3787
+ return typeof value === "number" ? `${value}px` : value;
3788
+ }
3789
+ function MarkdownEditor({
3790
+ initialContent = "",
3791
+ onChange,
3792
+ width = 700,
3793
+ height = 500,
3794
+ sanitizeEmbeddedHtml = true,
3795
+ className,
3796
+ onlyView = false,
3797
+ resizable = true
3798
+ }) {
3799
+ const [source, setSource] = (0, import_react9.useState)(initialContent);
3800
+ const [viewMode, setViewMode] = (0, import_react9.useState)("wysiwyg");
3801
+ const effectiveViewMode = onlyView ? "wysiwyg" : viewMode;
3802
+ const [linkPopover, setLinkPopover] = (0, import_react9.useState)(
3803
+ null
3804
+ );
3805
+ const onChangeRef = (0, import_react9.useRef)(onChange);
3806
+ onChangeRef.current = onChange;
3807
+ const sourceRef = (0, import_react9.useRef)(source);
3808
+ sourceRef.current = source;
3809
+ const extensions = (0, import_react9.useMemo)(
3810
+ () => createEditorExtensions({ sanitizeEmbeddedHtml }),
3811
+ [sanitizeEmbeddedHtml]
3812
+ );
3813
+ const editor = (0, import_react10.useEditor)(
3814
+ {
3815
+ extensions,
3816
+ content: markdownToEditorContent(sourceRef.current),
3817
+ editable: !onlyView,
3818
+ editorProps: {
3819
+ attributes: {
3820
+ role: "textbox",
3821
+ "aria-multiline": "true",
3822
+ "aria-label": "Editor de texto enriquecido"
3823
+ },
3824
+ handleDOMEvents: {
3825
+ click(view, event) {
3826
+ const target = event.target;
3827
+ if (!(target instanceof Element)) return false;
3828
+ const anchorEl = target.closest("a");
3829
+ if (anchorEl === null || !view.dom.contains(anchorEl)) {
3830
+ return false;
3831
+ }
3832
+ const linkType = view.state.schema.marks["link"];
3833
+ if (!linkType) return false;
3834
+ const pos = view.posAtDOM(anchorEl, 0);
3835
+ const $pos = view.state.doc.resolve(
3836
+ Math.min(pos + 1, view.state.doc.content.size)
3837
+ );
3838
+ const range = (0, import_core2.getMarkRange)($pos, linkType);
3839
+ if (!range) return false;
3840
+ const mark = $pos.marks().find((candidate) => candidate.type === linkType);
3841
+ const href = mark?.attrs["href"];
3842
+ if (href === void 0) return false;
3843
+ event.preventDefault();
3844
+ setLinkPopover({ url: href, range, anchor: anchorEl });
3845
+ return true;
3846
+ }
3847
+ }
3848
+ },
3849
+ onUpdate({ editor: currentEditor }) {
3850
+ const markdown = editorToMarkdown(currentEditor);
3851
+ sourceRef.current = markdown;
3852
+ setSource(markdown);
3853
+ onChangeRef.current?.(markdown);
3854
+ }
3855
+ },
3856
+ [sanitizeEmbeddedHtml, onlyView]
3857
+ );
3858
+ const toggleView = () => {
3859
+ if (viewMode === "wysiwyg") {
3860
+ setViewMode("markdown");
3861
+ } else {
3862
+ editor?.commands.setContent(
3863
+ markdownToEditorContent(sourceRef.current),
3864
+ false
3865
+ );
3866
+ setViewMode("wysiwyg");
3867
+ }
3868
+ };
3869
+ const handleSourceChange = (value) => {
3870
+ sourceRef.current = value;
3871
+ setSource(value);
3872
+ onChangeRef.current?.(value);
3873
+ };
3874
+ const closeLinkPopover = () => setLinkPopover(null);
3875
+ const saveLinkPopover = (newUrl) => {
3876
+ if (!editor || !linkPopover) return;
3877
+ editor.chain().focus().setTextSelection(linkPopover.range).extendMarkRange("link").setLink({ href: newUrl }).run();
3878
+ closeLinkPopover();
3879
+ };
3880
+ const removeLinkPopover = () => {
3881
+ if (!editor || !linkPopover) return;
3882
+ editor.chain().focus().setTextSelection(linkPopover.range).extendMarkRange("link").unsetLink().run();
3883
+ closeLinkPopover();
3884
+ };
3885
+ const rootClassName = [
3886
+ MarkdownEditor_default["root"],
3887
+ resizable ? MarkdownEditor_default["resizable"] : void 0,
3888
+ className
3889
+ ].filter(Boolean).join(" ");
3890
+ return /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(
3891
+ "div",
3892
+ {
3893
+ className: rootClassName,
3894
+ style: { width: toCssSize(width), height: toCssSize(height) },
3895
+ children: [
3896
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
3897
+ Toolbar,
3898
+ {
3899
+ editor,
3900
+ viewMode: effectiveViewMode,
3901
+ onToggleView: toggleView,
3902
+ source,
3903
+ sanitizeEmbeddedHtml,
3904
+ onlyView
3905
+ }
3906
+ ),
3907
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("div", { className: MarkdownEditor_default["content"], children: effectiveViewMode === "wysiwyg" ? /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(RenderedView, { editor }) : /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
3908
+ MarkdownSourceView,
3909
+ {
3910
+ value: source,
3911
+ onChange: handleSourceChange,
3912
+ readOnly: onlyView
3913
+ }
3914
+ ) }),
3915
+ linkPopover !== null && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(FloatingPanel, { anchor: linkPopover.anchor, autoFocus: true, children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
3916
+ LinkPopover,
3917
+ {
3918
+ url: linkPopover.url,
3919
+ onlyView,
3920
+ onNavigate: () => {
3921
+ window.open(linkPopover.url, "_blank", "noopener,noreferrer");
3922
+ closeLinkPopover();
3923
+ },
3924
+ onCopy: () => {
3925
+ void navigator.clipboard.writeText(linkPopover.url);
3926
+ closeLinkPopover();
3927
+ },
3928
+ onSave: saveLinkPopover,
3929
+ onRemove: removeLinkPopover,
3930
+ onClose: closeLinkPopover
3931
+ }
3932
+ ) })
3933
+ ]
3934
+ }
3935
+ );
3936
+ }
3937
+ // Annotate the CommonJS export names for ESM import in node:
3938
+ 0 && (module.exports = {
3939
+ MarkdownEditor
3940
+ });
3941
+ //# sourceMappingURL=index.cjs.map