@carto/meridian-ds 1.4.8 → 1.5.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/CHANGELOG.md CHANGED
@@ -4,6 +4,11 @@
4
4
 
5
5
  ## 1.0
6
6
 
7
+ ### 1.5.0
8
+
9
+ - Add `SplitButton` [#212](https://github.com/CartoDB/meridian-ds/pull/212)
10
+ - CodeArea: Add automatic text marking for markdown [#209](https://github.com/CartoDB/meridian-ds/pull/209)
11
+
7
12
  ### 1.4.8
8
13
 
9
14
  - Fix Category Widget Blanks [#210](https://github.com/CartoDB/meridian-ds/pull/210)
@@ -2,6 +2,32 @@
2
2
  const jsxRuntime = require("react/jsx-runtime");
3
3
  const React = require("react");
4
4
  const utils = require("@mui/material/utils");
5
+ const Icon$2 = () => /* @__PURE__ */ jsxRuntime.jsx("svg", { xmlns: "http://www.w3.org/2000/svg", fill: "none", children: /* @__PURE__ */ jsxRuntime.jsx(
6
+ "path",
7
+ {
8
+ fill: "currentColor",
9
+ fillRule: "evenodd",
10
+ d: "M12.01 11.83 15.18 15l1.41-1.41L12.01 9l-4.59 4.59L8.84 15z",
11
+ clipRule: "evenodd"
12
+ }
13
+ ) });
14
+ const BaseSvgIcon$2 = utils.createSvgIcon(Icon$2(), "ArrowUp");
15
+ function ArrowUp({ width, height, sx, ...props }, ref) {
16
+ return /* @__PURE__ */ jsxRuntime.jsx(
17
+ BaseSvgIcon$2,
18
+ {
19
+ ref,
20
+ viewBox: "0 0 24 24",
21
+ sx: {
22
+ width,
23
+ height: height || width,
24
+ ...sx
25
+ },
26
+ ...props
27
+ }
28
+ );
29
+ }
30
+ const ArrowUp$1 = React.forwardRef(ArrowUp);
5
31
  const Icon$1 = () => /* @__PURE__ */ jsxRuntime.jsx("svg", { xmlns: "http://www.w3.org/2000/svg", fill: "none", children: /* @__PURE__ */ jsxRuntime.jsx(
6
32
  "path",
7
33
  {
@@ -54,5 +80,6 @@ function OpenDiagonallyRight({ width, height, sx, ...props }, ref) {
54
80
  );
55
81
  }
56
82
  const OpenDiagonallyRight$1 = React.forwardRef(OpenDiagonallyRight);
83
+ exports.ArrowUp = ArrowUp$1;
57
84
  exports.CloseDiagonallyRight = CloseDiagonallyRight$1;
58
85
  exports.OpenDiagonallyRight = OpenDiagonallyRight$1;
@@ -1,6 +1,32 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
2
  import { forwardRef } from "react";
3
3
  import { createSvgIcon } from "@mui/material/utils";
4
+ const Icon$2 = () => /* @__PURE__ */ jsx("svg", { xmlns: "http://www.w3.org/2000/svg", fill: "none", children: /* @__PURE__ */ jsx(
5
+ "path",
6
+ {
7
+ fill: "currentColor",
8
+ fillRule: "evenodd",
9
+ d: "M12.01 11.83 15.18 15l1.41-1.41L12.01 9l-4.59 4.59L8.84 15z",
10
+ clipRule: "evenodd"
11
+ }
12
+ ) });
13
+ const BaseSvgIcon$2 = createSvgIcon(Icon$2(), "ArrowUp");
14
+ function ArrowUp({ width, height, sx, ...props }, ref) {
15
+ return /* @__PURE__ */ jsx(
16
+ BaseSvgIcon$2,
17
+ {
18
+ ref,
19
+ viewBox: "0 0 24 24",
20
+ sx: {
21
+ width,
22
+ height: height || width,
23
+ ...sx
24
+ },
25
+ ...props
26
+ }
27
+ );
28
+ }
29
+ const ArrowUp$1 = forwardRef(ArrowUp);
4
30
  const Icon$1 = () => /* @__PURE__ */ jsx("svg", { xmlns: "http://www.w3.org/2000/svg", fill: "none", children: /* @__PURE__ */ jsx(
5
31
  "path",
6
32
  {
@@ -54,6 +80,7 @@ function OpenDiagonallyRight({ width, height, sx, ...props }, ref) {
54
80
  }
55
81
  const OpenDiagonallyRight$1 = forwardRef(OpenDiagonallyRight);
56
82
  export {
83
+ ArrowUp$1 as A,
57
84
  CloseDiagonallyRight$1 as C,
58
85
  OpenDiagonallyRight$1 as O
59
86
  };
@@ -4,17 +4,17 @@ const jsxRuntime = require("react/jsx-runtime");
4
4
  const React = require("react");
5
5
  const material = require("@mui/material");
6
6
  const TablePaginationActions = require("../TablePaginationActions-CFGXm44W.cjs");
7
+ const ArrowDown = require("../ArrowDown-8fLj23Ge.cjs");
8
+ const OpenDiagonallyRight = require("../OpenDiagonallyRight-CM1tojUq.cjs");
7
9
  const reactIntl = require("react-intl");
8
10
  const iconsMaterial = require("@mui/icons-material");
9
11
  const Alert$1 = require("../Alert-BiOR9aar.cjs");
10
12
  require("cartocolor");
11
13
  const MenuItem = require("../MenuItem-Br2jY2lt.cjs");
12
- const ArrowDown = require("../ArrowDown-8fLj23Ge.cjs");
13
14
  const DatePicker$1 = require("@mui/x-date-pickers/DatePicker");
14
15
  const xDatePickers = require("@mui/x-date-pickers");
15
16
  const TimePicker$1 = require("@mui/x-date-pickers/TimePicker");
16
17
  const DateTimePicker$1 = require("@mui/x-date-pickers/DateTimePicker");
17
- const OpenDiagonallyRight = require("../OpenDiagonallyRight-BrRyCV4Q.cjs");
18
18
  const reactCodemirror2 = require("react-codemirror2");
19
19
  const colors = require("@mui/material/colors");
20
20
  require("codemirror/lib/codemirror.css");
@@ -100,6 +100,90 @@ function _Button({
100
100
  );
101
101
  }
102
102
  const Button = React.forwardRef(_Button);
103
+ const ButtonGroup = material.styled(material.ButtonGroup)(({ theme, size }) => ({
104
+ "& .MuiButton-root:last-child": {
105
+ padding: 0,
106
+ minWidth: size === "small" ? theme.spacing(3) : size === "large" ? theme.spacing(6) : theme.spacing(4)
107
+ }
108
+ }));
109
+ function SplitButton({
110
+ options,
111
+ onClick,
112
+ variant,
113
+ size,
114
+ color,
115
+ ...otherProps
116
+ }) {
117
+ var _a;
118
+ const [open, setOpen] = React.useState(false);
119
+ const anchorRef = React.useRef(null);
120
+ const [selectedIndex, setSelectedIndex] = React.useState(0);
121
+ const handleClick = () => {
122
+ onClick(options[selectedIndex]);
123
+ };
124
+ const handleMenuItemClick = (_, index) => {
125
+ setSelectedIndex(index);
126
+ setOpen(false);
127
+ };
128
+ const handleToggle = () => {
129
+ setOpen((prevOpen) => !prevOpen);
130
+ };
131
+ const handleClose = (event) => {
132
+ var _a2;
133
+ if ((_a2 = anchorRef.current) == null ? void 0 : _a2.contains(event.target)) {
134
+ return;
135
+ }
136
+ setOpen(false);
137
+ };
138
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
139
+ /* @__PURE__ */ jsxRuntime.jsxs(
140
+ ButtonGroup,
141
+ {
142
+ "data-name": "split-button",
143
+ ref: anchorRef,
144
+ variant,
145
+ size,
146
+ color,
147
+ ...otherProps,
148
+ children: [
149
+ /* @__PURE__ */ jsxRuntime.jsx(material.Button, { onClick: handleClick, children: (_a = options[selectedIndex]) == null ? void 0 : _a.label }),
150
+ /* @__PURE__ */ jsxRuntime.jsx(material.Button, { onClick: handleToggle, children: open ? /* @__PURE__ */ jsxRuntime.jsx(OpenDiagonallyRight.ArrowUp, {}) : /* @__PURE__ */ jsxRuntime.jsx(ArrowDown.ArrowDown, {}) })
151
+ ]
152
+ }
153
+ ),
154
+ /* @__PURE__ */ jsxRuntime.jsx(
155
+ material.Popper,
156
+ {
157
+ sx: { zIndex: 1 },
158
+ open,
159
+ anchorEl: anchorRef.current,
160
+ role: void 0,
161
+ transition: true,
162
+ disablePortal: true,
163
+ placement: "bottom-end",
164
+ children: ({ TransitionProps, placement }) => /* @__PURE__ */ jsxRuntime.jsx(
165
+ material.Grow,
166
+ {
167
+ ...TransitionProps,
168
+ style: {
169
+ transformOrigin: placement === "bottom" ? "center top" : "center bottom"
170
+ },
171
+ children: /* @__PURE__ */ jsxRuntime.jsx(material.Paper, { elevation: 8, children: /* @__PURE__ */ jsxRuntime.jsx(material.ClickAwayListener, { onClickAway: handleClose, children: /* @__PURE__ */ jsxRuntime.jsx(material.MenuList, { autoFocusItem: true, sx: { paddingY: 1 }, children: options.map((option, index) => /* @__PURE__ */ jsxRuntime.jsx(
172
+ material.MenuItem,
173
+ {
174
+ disabled: option.disabled,
175
+ selected: index === selectedIndex,
176
+ onClick: (event) => handleMenuItemClick(event, index),
177
+ children: option.label
178
+ },
179
+ option.label
180
+ )) }) }) })
181
+ }
182
+ )
183
+ }
184
+ )
185
+ ] });
186
+ }
103
187
  const Root$5 = material.styled(material.Box)(({ theme }) => ({
104
188
  display: "flex",
105
189
  alignItems: "center",
@@ -3114,8 +3198,9 @@ const CodeAreaTheme = material.styled(material.Box, {
3114
3198
  right: 0,
3115
3199
  zIndex: 1
3116
3200
  },
3117
- "& .pre.CodeMirror-line, .CodeMirror pre.CodeMirror-line-like, & .cm-bracket": {
3118
- color: theme.palette.text.primary
3201
+ ".CodeMirror pre.CodeMirror-line, .CodeMirror pre.CodeMirror-line-like, & .cm-bracket": {
3202
+ color: theme.palette.text.primary,
3203
+ fontVariantLigatures: "no-common-ligatures"
3119
3204
  },
3120
3205
  "& .CodeMirror pre.CodeMirror-placeholder": {
3121
3206
  color: theme.palette.text.hint
@@ -3133,7 +3218,7 @@ const CodeAreaTheme = material.styled(material.Box, {
3133
3218
  "& .cm-number, & .cm-property, & .cm-builtin": {
3134
3219
  color: colors.red[700]
3135
3220
  },
3136
- "& .cm-comment": {
3221
+ "& .cm-comment, & .cm-quote": {
3137
3222
  color: theme.palette.text.secondary
3138
3223
  },
3139
3224
  "& .cm-variable": {
@@ -3142,9 +3227,18 @@ const CodeAreaTheme = material.styled(material.Box, {
3142
3227
  "& .cm-variable-2": {
3143
3228
  color: theme.palette.text.primary
3144
3229
  },
3145
- "& .cm-punctuation, & .cm-def, ": {
3230
+ "& .cm-punctuation, & .cm-def": {
3146
3231
  color: colors.blue[800]
3147
3232
  },
3233
+ "& .cm-image-alt-text, & .cm-link": {
3234
+ color: colors.green[800],
3235
+ textDecoration: "none"
3236
+ },
3237
+ // Custom inline link styling .cm-inline-url
3238
+ "& .cm-url, & .cm-inline-url": {
3239
+ color: colors.blue[800],
3240
+ textDecoration: "none"
3241
+ },
3148
3242
  "& .cm-variable-3, & .cm-type": {
3149
3243
  color: colors.indigo[800]
3150
3244
  },
@@ -3158,20 +3252,23 @@ const CodeAreaTheme = material.styled(material.Box, {
3158
3252
  "& .CodeMirror-selected": {
3159
3253
  background: colors.blue[800]
3160
3254
  },
3161
- "& .cm-header-1": {
3162
- fontSize: theme.typography.h2.fontSize
3255
+ "& .cm-header": {
3256
+ color: colors.red[700],
3257
+ ...theme.typography.code3,
3258
+ fontWeight: theme.typography.fontWeightBold
3163
3259
  },
3164
- "& .cm-header-2": {
3165
- fontSize: theme.typography.h3.fontSize
3260
+ "& .cm-header-4, & .cm-header-5, & .cm-header-6": {
3261
+ fontWeight: theme.typography.fontWeightRegular
3166
3262
  },
3167
- "& .cm-header-3": {
3168
- fontSize: theme.typography.h4.fontSize
3169
- },
3170
- "& .cm-header-4": {
3171
- fontSize: theme.typography.h5.fontSize
3263
+ // Custom inline code styling
3264
+ "& .cm-inline-code": {
3265
+ backgroundColor: theme.palette.black[4],
3266
+ color: colors.purple[500]
3172
3267
  },
3173
- "& .cm-header-5": {
3174
- fontSize: theme.typography.h6.fontSize
3268
+ // Custom code block styling
3269
+ "& .cm-code-block": {
3270
+ backgroundColor: theme.palette.black[4],
3271
+ marginRight: theme.spacing(2)
3175
3272
  },
3176
3273
  ...size === "small" && {
3177
3274
  "& .CodeMirror": {
@@ -3207,6 +3304,100 @@ function findCodeAreaControlCodeOccurrences(content) {
3207
3304
  }
3208
3305
  return matches;
3209
3306
  }
3307
+ const editorMarkers = /* @__PURE__ */ new WeakMap();
3308
+ function clearMarkersForClass(editor, className) {
3309
+ var _a, _b;
3310
+ const markers = (_a = editorMarkers.get(editor)) == null ? void 0 : _a.get(className);
3311
+ if (!markers) return;
3312
+ markers.forEach((marker) => {
3313
+ if (marker.find()) {
3314
+ marker.clear();
3315
+ }
3316
+ });
3317
+ (_b = editorMarkers.get(editor)) == null ? void 0 : _b.delete(className);
3318
+ }
3319
+ function storeMarkersForClass(editor, className, markers) {
3320
+ if (!editorMarkers.has(editor)) {
3321
+ editorMarkers.set(editor, /* @__PURE__ */ new Map());
3322
+ }
3323
+ const editorMap = editorMarkers.get(editor);
3324
+ if (editorMap) {
3325
+ editorMap.set(className, markers);
3326
+ }
3327
+ }
3328
+ function CodeAreaMarkTextPattern(editor, pattern, options, excludePatterns) {
3329
+ const { className } = options;
3330
+ clearMarkersForClass(editor, className);
3331
+ const doc = editor.getDoc();
3332
+ const content = doc.getValue();
3333
+ const excludeRanges = (excludePatterns == null ? void 0 : excludePatterns.flatMap(
3334
+ (excludePattern) => Array.from(content.matchAll(excludePattern), (match) => ({
3335
+ start: match.index,
3336
+ end: match.index + match[0].length
3337
+ }))
3338
+ )) ?? [];
3339
+ const markers = Array.from(content.matchAll(pattern)).filter((match) => {
3340
+ if (excludeRanges.some(
3341
+ (range) => match.index >= range.start && match.index < range.end
3342
+ )) {
3343
+ return false;
3344
+ }
3345
+ return !match[1] || match[1].trim().length > 0;
3346
+ }).map((match) => {
3347
+ const startPos = doc.posFromIndex(match.index);
3348
+ const endPos = doc.posFromIndex(match.index + match[0].length);
3349
+ return editor.markText(startPos, endPos, {
3350
+ atomic: false,
3351
+ clearOnEnter: false,
3352
+ ...options
3353
+ });
3354
+ });
3355
+ if (markers.length > 0) {
3356
+ storeMarkersForClass(editor, className, markers);
3357
+ }
3358
+ }
3359
+ function markInlineCode(editor, className = "cm-inline-code") {
3360
+ const inlineCodePattern = /`([^`\n\r]+)`/g;
3361
+ const codeBlockPattern = /```[\s\S]*?```/g;
3362
+ CodeAreaMarkTextPattern(
3363
+ editor,
3364
+ inlineCodePattern,
3365
+ {
3366
+ className
3367
+ },
3368
+ [codeBlockPattern]
3369
+ );
3370
+ }
3371
+ function markInlineLinks(editor, className = "cm-inline-url") {
3372
+ const inlineLinkPattern = /<((?:https?:\/\/[^\s<>]+)|(?:[^\s<>@]+@[^\s<>@]+\.[^\s<>@]+))>/g;
3373
+ const codeBlockPattern = /```[\s\S]*?```/g;
3374
+ CodeAreaMarkTextPattern(
3375
+ editor,
3376
+ inlineLinkPattern,
3377
+ {
3378
+ className
3379
+ },
3380
+ [codeBlockPattern]
3381
+ );
3382
+ }
3383
+ function markCodeBlocks(editor, className = "cm-code-block") {
3384
+ const doc = editor.getDoc();
3385
+ const content = doc.getValue();
3386
+ const lineCount = content.split("\n").length;
3387
+ for (let i = 0; i < lineCount; i++) {
3388
+ ["background", "wrap", "text"].forEach(
3389
+ (where) => editor.removeLineClass(i, where, className)
3390
+ );
3391
+ }
3392
+ const codeBlockPattern = /```[\s\S]*?(?:```|$)/g;
3393
+ Array.from(content.matchAll(codeBlockPattern)).forEach((match) => {
3394
+ const startPos = doc.posFromIndex(match.index);
3395
+ const endPos = doc.posFromIndex(match.index + match[0].length);
3396
+ for (let lineNum = startPos.line; lineNum <= endPos.line; lineNum++) {
3397
+ editor.addLineClass(lineNum, "wrap", className);
3398
+ }
3399
+ });
3400
+ }
3210
3401
  function foldCode(editor, { from, to }) {
3211
3402
  editor.foldCode(
3212
3403
  0,
@@ -3247,6 +3438,7 @@ function CodeAreaInput({
3247
3438
  const codeMirrorOptions = {
3248
3439
  mode: "sql",
3249
3440
  theme: "light",
3441
+ addModeClass: true,
3250
3442
  lineNumbers: true,
3251
3443
  lineWrapping: true,
3252
3444
  extraKeys: { "Ctrl-Space": "autocomplete" },
@@ -3277,6 +3469,13 @@ function CodeAreaInput({
3277
3469
  }
3278
3470
  initialFoldingDoneRef.current = true;
3279
3471
  }, [value, editor, autoFoldControlBlocks]);
3472
+ React.useEffect(() => {
3473
+ const mode = typeof (options == null ? void 0 : options.mode) === "object" && options.mode !== null ? options.mode.name : options == null ? void 0 : options.mode;
3474
+ if (mode !== "markdown" || !editor || !value) return;
3475
+ markInlineCode(editor);
3476
+ markInlineLinks(editor);
3477
+ markCodeBlocks(editor);
3478
+ }, [editor, value, options == null ? void 0 : options.mode]);
3280
3479
  return /* @__PURE__ */ jsxRuntime.jsxs(
3281
3480
  CodeAreaTheme,
3282
3481
  {
@@ -4500,6 +4699,7 @@ exports.CodeAreaField = CodeAreaField;
4500
4699
  exports.CodeAreaFooter = CodeAreaFooter;
4501
4700
  exports.CodeAreaHeader = CodeAreaHeader;
4502
4701
  exports.CodeAreaInput = CodeAreaInput;
4702
+ exports.CodeAreaMarkTextPattern = CodeAreaMarkTextPattern;
4503
4703
  exports.CopiableComponent = CopiableComponent;
4504
4704
  exports.CreatableAutocomplete = CreatableAutocomplete;
4505
4705
  exports.DatePicker = DatePicker;
@@ -4524,6 +4724,7 @@ exports.MultipleSelectField = MultipleSelectField;
4524
4724
  exports.PasswordField = PasswordField;
4525
4725
  exports.SelectField = SelectField;
4526
4726
  exports.Snackbar = Snackbar;
4727
+ exports.SplitButton = SplitButton;
4527
4728
  exports.Tag = Tag;
4528
4729
  exports.TimePicker = TimePicker;
4529
4730
  exports.ToggleButtonGroup = ToggleButtonGroup;