@carto/meridian-ds 2.4.0-structure.1 → 2.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
@@ -2,12 +2,16 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 2.0
6
+
7
+ ### 2.5.0
8
+
5
9
  - Move widgets files: Co-located Files with Explicit Exports [#259](https://github.com/CartoDB/meridian-ds/pull/259)
6
10
  - Move the Mui component's stories to the `src/theme/` folder [#260](https://github.com/CartoDB/meridian-ds/pull/260)
7
11
  - Integrate Chromatic visual testing tool in CI [#236](https://github.com/CartoDB/meridian-ds/pull/236)
8
12
  - Add cursor rules, CODEOWNERS, and fix dependabot groups [#242](https://github.com/CartoDB/meridian-ds/pull/242)
9
-
10
- ## 2.0
13
+ - Support `useAutocompletion` in `CodeAreaField` component [#270](https://github.com/CartoDB/meridian-ds/pull/270)
14
+ - Support Symbol Highlighting in `CodeAreaField` component [#271](https://github.com/CartoDB/meridian-ds/pull/271)
11
15
 
12
16
  ### 2.4.0
13
17
 
@@ -41,6 +41,7 @@ require("codemirror/addon/fold/indent-fold.js");
41
41
  require("codemirror/addon/fold/markdown-fold.js");
42
42
  require("codemirror/addon/fold/comment-fold.js");
43
43
  const ClickAwayListener = require("@mui/material/ClickAwayListener");
44
+ const DOMPurify = require("dompurify");
44
45
  const StyledMenu = material.styled(material.Menu, {
45
46
  shouldForwardProp: (prop) => !["extended", "width", "height"].includes(prop)
46
47
  })(({ extended, width, height }) => ({
@@ -4105,6 +4106,22 @@ function markCodeBlocks(editor, className = "cm-code-block") {
4105
4106
  }
4106
4107
  });
4107
4108
  }
4109
+ function markTextPrecededBySymbol(editor, symbol, className = "cm-symbol-text") {
4110
+ const escapedSymbol = symbol.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
4111
+ const codeBlockPattern = /```[\s\S]*?```/g;
4112
+ const symbolTextPattern = new RegExp(
4113
+ `(?<=^|\\s)(${escapedSymbol}[^\\s]+)`,
4114
+ "g"
4115
+ );
4116
+ CodeAreaMarkTextPattern(
4117
+ editor,
4118
+ symbolTextPattern,
4119
+ {
4120
+ className
4121
+ },
4122
+ [codeBlockPattern]
4123
+ );
4124
+ }
4108
4125
  function foldCode(editor, { from, to }) {
4109
4126
  editor.foldCode(
4110
4127
  0,
@@ -4222,6 +4239,11 @@ function CodeAreaInput({
4222
4239
  {
4223
4240
  ...props,
4224
4241
  value: defaultValue,
4242
+ editorDidMount: (editor2) => {
4243
+ editorRef.current = editor2;
4244
+ setEditor(editor2);
4245
+ onEditorDidMount == null ? void 0 : onEditorDidMount(editor2);
4246
+ },
4225
4247
  options: codeMirrorOptions,
4226
4248
  onBlur: (editor2) => {
4227
4249
  onBlur == null ? void 0 : onBlur(editor2.getValue());
@@ -5388,6 +5410,77 @@ function CodeAreaDialog({
5388
5410
  }
5389
5411
  );
5390
5412
  }
5413
+ const useAutocompletion = (editor, config) => {
5414
+ const { triggers } = config;
5415
+ React.useEffect(() => {
5416
+ if (!editor) return;
5417
+ const closeHints = (cm) => {
5418
+ var _a;
5419
+ const active = (_a = cm.state) == null ? void 0 : _a.completionActive;
5420
+ if (active == null ? void 0 : active.close) active.close();
5421
+ };
5422
+ const showAutocomplete = (cm) => {
5423
+ const cursor = cm.getCursor();
5424
+ const line = cm.getLine(cursor.line);
5425
+ const textBeforeCursor = line.slice(0, cursor.ch);
5426
+ let atIndex = -1;
5427
+ let foundTriggerConfig = null;
5428
+ for (let i = textBeforeCursor.length - 1; i >= 0; i--) {
5429
+ const char = textBeforeCursor[i];
5430
+ const triggerConfig = triggers.find((t) => t.symbol === char);
5431
+ if (triggerConfig) {
5432
+ const beforeTrigger = textBeforeCursor.slice(0, i);
5433
+ if (beforeTrigger.length === 0 || beforeTrigger.endsWith(" ")) {
5434
+ atIndex = i;
5435
+ foundTriggerConfig = triggerConfig;
5436
+ break;
5437
+ }
5438
+ }
5439
+ }
5440
+ if (atIndex === -1 || !foundTriggerConfig) {
5441
+ closeHints(cm);
5442
+ return;
5443
+ }
5444
+ const query = textBeforeCursor.slice(atIndex + 1);
5445
+ if (query.includes(" ")) {
5446
+ closeHints(cm);
5447
+ return;
5448
+ }
5449
+ const itemsForTrigger = foundTriggerConfig.items;
5450
+ const filtered = itemsForTrigger.filter(
5451
+ (item) => item.value.toLowerCase().includes(query.toLowerCase())
5452
+ );
5453
+ if (filtered.length === 0) {
5454
+ closeHints(cm);
5455
+ return;
5456
+ }
5457
+ cm.showHint({
5458
+ hint: () => ({
5459
+ list: filtered.map((item) => ({
5460
+ text: item.value + " ",
5461
+ render: (element) => {
5462
+ element.innerHTML = DOMPurify.sanitize(item.html);
5463
+ }
5464
+ })),
5465
+ from: { line: cursor.line, ch: atIndex + 1 },
5466
+ to: cursor
5467
+ }),
5468
+ completeSingle: false,
5469
+ closeOnUnfocus: true
5470
+ });
5471
+ };
5472
+ const handleChange = () => showAutocomplete(editor);
5473
+ const handleKeydown = (cm, event) => {
5474
+ if (event.key === "Escape") closeHints(cm);
5475
+ };
5476
+ editor.on("change", handleChange);
5477
+ editor.on("keydown", handleKeydown);
5478
+ return () => {
5479
+ editor.off("change", handleChange);
5480
+ editor.off("keydown", handleKeydown);
5481
+ };
5482
+ }, [editor, triggers]);
5483
+ };
5391
5484
  exports.TablePaginationActions = TablePaginationActions.TablePaginationActions;
5392
5485
  exports.Typography = TablePaginationActions.Typography;
5393
5486
  exports.Alert = Link.Alert;
@@ -5449,5 +5542,7 @@ exports.copyString = copyString;
5449
5542
  exports.createAutocompleteGroupByList = createAutocompleteGroupByList;
5450
5543
  exports.dialogDimensionsBySize = dialogDimensionsBySize;
5451
5544
  exports.isAutocompleteListGroupHeader = isAutocompleteListGroupHeader;
5545
+ exports.markTextPrecededBySymbol = markTextPrecededBySymbol;
5452
5546
  exports.useAutocomplete = useAutocomplete;
5547
+ exports.useAutocompletion = useAutocompletion;
5453
5548
  exports.useCopyValue = useCopyValue;
@@ -41,6 +41,7 @@ import "codemirror/addon/fold/indent-fold.js";
41
41
  import "codemirror/addon/fold/markdown-fold.js";
42
42
  import "codemirror/addon/fold/comment-fold.js";
43
43
  import ClickAwayListener$1 from "@mui/material/ClickAwayListener";
44
+ import DOMPurify from "dompurify";
44
45
  const StyledMenu = styled(Menu$2, {
45
46
  shouldForwardProp: (prop) => !["extended", "width", "height"].includes(prop)
46
47
  })(({ extended, width, height }) => ({
@@ -4105,6 +4106,22 @@ function markCodeBlocks(editor, className = "cm-code-block") {
4105
4106
  }
4106
4107
  });
4107
4108
  }
4109
+ function markTextPrecededBySymbol(editor, symbol, className = "cm-symbol-text") {
4110
+ const escapedSymbol = symbol.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
4111
+ const codeBlockPattern = /```[\s\S]*?```/g;
4112
+ const symbolTextPattern = new RegExp(
4113
+ `(?<=^|\\s)(${escapedSymbol}[^\\s]+)`,
4114
+ "g"
4115
+ );
4116
+ CodeAreaMarkTextPattern(
4117
+ editor,
4118
+ symbolTextPattern,
4119
+ {
4120
+ className
4121
+ },
4122
+ [codeBlockPattern]
4123
+ );
4124
+ }
4108
4125
  function foldCode(editor, { from, to }) {
4109
4126
  editor.foldCode(
4110
4127
  0,
@@ -4222,6 +4239,11 @@ function CodeAreaInput({
4222
4239
  {
4223
4240
  ...props,
4224
4241
  value: defaultValue,
4242
+ editorDidMount: (editor2) => {
4243
+ editorRef.current = editor2;
4244
+ setEditor(editor2);
4245
+ onEditorDidMount == null ? void 0 : onEditorDidMount(editor2);
4246
+ },
4225
4247
  options: codeMirrorOptions,
4226
4248
  onBlur: (editor2) => {
4227
4249
  onBlur == null ? void 0 : onBlur(editor2.getValue());
@@ -5388,6 +5410,77 @@ function CodeAreaDialog({
5388
5410
  }
5389
5411
  );
5390
5412
  }
5413
+ const useAutocompletion = (editor, config) => {
5414
+ const { triggers } = config;
5415
+ useEffect(() => {
5416
+ if (!editor) return;
5417
+ const closeHints = (cm) => {
5418
+ var _a;
5419
+ const active = (_a = cm.state) == null ? void 0 : _a.completionActive;
5420
+ if (active == null ? void 0 : active.close) active.close();
5421
+ };
5422
+ const showAutocomplete = (cm) => {
5423
+ const cursor = cm.getCursor();
5424
+ const line = cm.getLine(cursor.line);
5425
+ const textBeforeCursor = line.slice(0, cursor.ch);
5426
+ let atIndex = -1;
5427
+ let foundTriggerConfig = null;
5428
+ for (let i = textBeforeCursor.length - 1; i >= 0; i--) {
5429
+ const char = textBeforeCursor[i];
5430
+ const triggerConfig = triggers.find((t) => t.symbol === char);
5431
+ if (triggerConfig) {
5432
+ const beforeTrigger = textBeforeCursor.slice(0, i);
5433
+ if (beforeTrigger.length === 0 || beforeTrigger.endsWith(" ")) {
5434
+ atIndex = i;
5435
+ foundTriggerConfig = triggerConfig;
5436
+ break;
5437
+ }
5438
+ }
5439
+ }
5440
+ if (atIndex === -1 || !foundTriggerConfig) {
5441
+ closeHints(cm);
5442
+ return;
5443
+ }
5444
+ const query = textBeforeCursor.slice(atIndex + 1);
5445
+ if (query.includes(" ")) {
5446
+ closeHints(cm);
5447
+ return;
5448
+ }
5449
+ const itemsForTrigger = foundTriggerConfig.items;
5450
+ const filtered = itemsForTrigger.filter(
5451
+ (item) => item.value.toLowerCase().includes(query.toLowerCase())
5452
+ );
5453
+ if (filtered.length === 0) {
5454
+ closeHints(cm);
5455
+ return;
5456
+ }
5457
+ cm.showHint({
5458
+ hint: () => ({
5459
+ list: filtered.map((item) => ({
5460
+ text: item.value + " ",
5461
+ render: (element) => {
5462
+ element.innerHTML = DOMPurify.sanitize(item.html);
5463
+ }
5464
+ })),
5465
+ from: { line: cursor.line, ch: atIndex + 1 },
5466
+ to: cursor
5467
+ }),
5468
+ completeSingle: false,
5469
+ closeOnUnfocus: true
5470
+ });
5471
+ };
5472
+ const handleChange = () => showAutocomplete(editor);
5473
+ const handleKeydown = (cm, event) => {
5474
+ if (event.key === "Escape") closeHints(cm);
5475
+ };
5476
+ editor.on("change", handleChange);
5477
+ editor.on("keydown", handleKeydown);
5478
+ return () => {
5479
+ editor.off("change", handleChange);
5480
+ editor.off("keydown", handleKeydown);
5481
+ };
5482
+ }, [editor, triggers]);
5483
+ };
5391
5484
  export {
5392
5485
  AUTOCOMPLETE_GROUP_HEADER_PROPERTY,
5393
5486
  AccordionGroup,
@@ -5450,6 +5543,8 @@ export {
5450
5543
  createAutocompleteGroupByList,
5451
5544
  dialogDimensionsBySize,
5452
5545
  isAutocompleteListGroupHeader,
5546
+ markTextPrecededBySymbol,
5453
5547
  useAutocomplete,
5548
+ useAutocompletion,
5454
5549
  useCopyValue
5455
5550
  };
@@ -1 +1 @@
1
- {"version":3,"file":"CodeAreaInput.d.ts","sourceRoot":"","sources":["../../../../../src/components/organisms/CodeArea/CodeAreaInput.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AAexC,OAAO,+BAA+B,CAAA;AACtC,OAAO,8BAA8B,CAAA;AAIrC,OAAO,4BAA4B,CAAA;AACnC,OAAO,0CAA0C,CAAA;AACjD,OAAO,wCAAwC,CAAA;AAC/C,OAAO,sCAAsC,CAAA;AAC7C,OAAO,gCAAgC,CAAA;AACvC,OAAO,kCAAkC,CAAA;AAGzC,OAAO,sCAAsC,CAAA;AAC7C,OAAO,mCAAmC,CAAA;AAC1C,OAAO,qCAAqC,CAAA;AAC5C,OAAO,oCAAoC,CAAA;AAC3C,OAAO,2CAA2C,CAAA;AAClD,OAAO,wCAAwC,CAAA;AAG/C,OAAO,mCAAmC,CAAA;AAC1C,OAAO,qCAAqC,CAAA;AAC5C,OAAO,sCAAsC,CAAA;AAC7C,OAAO,qCAAqC,CAAA;AAC5C,OAAO,mCAAmC,CAAA;AAC1C,OAAO,sCAAsC,CAAA;AAC7C,OAAO,wCAAwC,CAAA;AAC/C,OAAO,uCAAuC,CAAA;AAE9C,UAAU,kBAAkB;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,OAAO,CAAC,EAAE;QACR,IAAI,CAAC,EAAE,MAAM,GAAG;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;SAAE,CAAA;QACxD,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;KACvB,CAAA;IACD,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,gBAAgB,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAA;IAC3C,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;IAClC,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;IAChC,OAAO,CAAC,EAAE,MAAM,IAAI,CAAA;IACpB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,IAAI,CAAC,EAAE,OAAO,GAAG,QAAQ,CAAA;IACzB,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACxB,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,yEAAyE;IACzE,qBAAqB,CAAC,EAAE,OAAO,CAAA;CAChC;AAmBD,MAAM,CAAC,OAAO,UAAU,aAAa,CAAC,EACpC,OAAO,EACP,KAAK,EACL,YAAY,EACZ,EAAE,EACF,gBAAgB,EAChB,QAAQ,EACR,MAAM,EACN,OAAO,EACP,WAAW,EACX,QAAQ,EACR,IAAc,EACd,MAAM,EACN,qBAAqB,EACrB,aAAa,EAAE,UAAU,EACzB,YAAY,EAAE,SAAS,EACvB,GAAG,KAAK,EACT,EAAE,kBAAkB,2CAwHpB"}
1
+ {"version":3,"file":"CodeAreaInput.d.ts","sourceRoot":"","sources":["../../../../../src/components/organisms/CodeArea/CodeAreaInput.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AAexC,OAAO,+BAA+B,CAAA;AACtC,OAAO,8BAA8B,CAAA;AAIrC,OAAO,4BAA4B,CAAA;AACnC,OAAO,0CAA0C,CAAA;AACjD,OAAO,wCAAwC,CAAA;AAC/C,OAAO,sCAAsC,CAAA;AAC7C,OAAO,gCAAgC,CAAA;AACvC,OAAO,kCAAkC,CAAA;AAGzC,OAAO,sCAAsC,CAAA;AAC7C,OAAO,mCAAmC,CAAA;AAC1C,OAAO,qCAAqC,CAAA;AAC5C,OAAO,oCAAoC,CAAA;AAC3C,OAAO,2CAA2C,CAAA;AAClD,OAAO,wCAAwC,CAAA;AAG/C,OAAO,mCAAmC,CAAA;AAC1C,OAAO,qCAAqC,CAAA;AAC5C,OAAO,sCAAsC,CAAA;AAC7C,OAAO,qCAAqC,CAAA;AAC5C,OAAO,mCAAmC,CAAA;AAC1C,OAAO,sCAAsC,CAAA;AAC7C,OAAO,wCAAwC,CAAA;AAC/C,OAAO,uCAAuC,CAAA;AAE9C,UAAU,kBAAkB;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,OAAO,CAAC,EAAE;QACR,IAAI,CAAC,EAAE,MAAM,GAAG;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;SAAE,CAAA;QACxD,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;KACvB,CAAA;IACD,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,gBAAgB,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAA;IAC3C,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;IAClC,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;IAChC,OAAO,CAAC,EAAE,MAAM,IAAI,CAAA;IACpB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,IAAI,CAAC,EAAE,OAAO,GAAG,QAAQ,CAAA;IACzB,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACxB,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,yEAAyE;IACzE,qBAAqB,CAAC,EAAE,OAAO,CAAA;CAChC;AAmBD,MAAM,CAAC,OAAO,UAAU,aAAa,CAAC,EACpC,OAAO,EACP,KAAK,EACL,YAAY,EACZ,EAAE,EACF,gBAAgB,EAChB,QAAQ,EACR,MAAM,EACN,OAAO,EACP,WAAW,EACX,QAAQ,EACR,IAAc,EACd,MAAM,EACN,qBAAqB,EACrB,aAAa,EAAE,UAAU,EACzB,YAAY,EAAE,SAAS,EACvB,GAAG,KAAK,EACT,EAAE,kBAAkB,2CA6HpB"}
@@ -6,5 +6,7 @@ export { default as CodeAreaField } from './CodeAreaField';
6
6
  export { default as CodeAreaFooter } from './CodeAreaFooter';
7
7
  export { default as CodeAreaHeader } from './CodeAreaHeader';
8
8
  export { default as CodeAreaInput } from './CodeAreaInput';
9
- export { CodeAreaMarkTextPattern } from './utils';
9
+ export { useAutocompletion } from './useAutocompletion';
10
+ export { CodeAreaMarkTextPattern, markTextPrecededBySymbol } from './utils';
11
+ export type { AutocompletionConfig, AutocompleteItem, TriggerConfig, } from './useAutocompletion';
10
12
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/components/organisms/CodeArea/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,iCAAiC,CAAA;AAC3E,OAAO,EAAE,OAAO,IAAI,qBAAqB,EAAE,MAAM,wCAAwC,CAAA;AACzF,OAAO,EAAE,OAAO,IAAI,0BAA0B,EAAE,MAAM,6CAA6C,CAAA;AACnG,OAAO,EAAE,OAAO,IAAI,mBAAmB,EAAE,MAAM,sCAAsC,CAAA;AACrF,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC1D,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAC5D,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAC5D,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC1D,OAAO,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/components/organisms/CodeArea/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,iCAAiC,CAAA;AAC3E,OAAO,EAAE,OAAO,IAAI,qBAAqB,EAAE,MAAM,wCAAwC,CAAA;AACzF,OAAO,EAAE,OAAO,IAAI,0BAA0B,EAAE,MAAM,6CAA6C,CAAA;AACnG,OAAO,EAAE,OAAO,IAAI,mBAAmB,EAAE,MAAM,sCAAsC,CAAA;AACrF,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC1D,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAC5D,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAC5D,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AACvD,OAAO,EAAE,uBAAuB,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAA;AAE3E,YAAY,EACV,oBAAoB,EACpB,gBAAgB,EAChB,aAAa,GACd,MAAM,qBAAqB,CAAA"}
@@ -0,0 +1,62 @@
1
+ import { Editor } from 'codemirror';
2
+ export interface AutocompleteItem {
3
+ /** The value to insert when selected */
4
+ value: string;
5
+ /** The HTML content to display in the dropdown */
6
+ html: string;
7
+ }
8
+ export interface TriggerConfig {
9
+ /** The trigger character (e.g., '@', '/', '#') */
10
+ symbol: string;
11
+ /** List of items to show for this trigger */
12
+ items: AutocompleteItem[];
13
+ }
14
+ export interface AutocompletionConfig {
15
+ /** Array of trigger configurations */
16
+ triggers: TriggerConfig[];
17
+ }
18
+ /**
19
+ * Hook for adding autocompletion functionality to CodeMirror editors
20
+ *
21
+ * @param editor - The CodeMirror editor instance
22
+ * @param config - Configuration object for autocompletion behavior
23
+ *
24
+ * @example
25
+ * ```typescript
26
+ * const [editor, setEditor] = useState<Editor | null>(null)
27
+ *
28
+ * useAutocompletion(editor, {
29
+ * triggers: [
30
+ * {
31
+ * symbol: '@',
32
+ * items: [
33
+ * { value: 'user1', html: '<div class="user-item">👤 John Doe</div>' },
34
+ * { value: 'admin1', html: '<div class="admin-item">👑 Alice Admin</div>' }
35
+ * ]
36
+ * },
37
+ * {
38
+ * symbol: '/',
39
+ * items: [
40
+ * { value: 'help', html: '<div class="command-item">📖 Show help</div>' },
41
+ * { value: 'save', html: '<div class="command-item">💾 Save document</div>' }
42
+ * ]
43
+ * },
44
+ * {
45
+ * symbol: '#',
46
+ * items: [
47
+ * { value: 'urgent', html: '<div class="tag-item">🔴 Urgent</div>' },
48
+ * { value: 'review', html: '<div class="tag-item">👀 Needs review</div>' }
49
+ * ]
50
+ * }
51
+ * ]
52
+ * })
53
+ *
54
+ * const handleEditorMount = (editor: Editor) => {
55
+ * setEditor(editor)
56
+ * }
57
+ *
58
+ * <CodeAreaField ... onEditorDidMount={handleEditorMount} />
59
+ * ```
60
+ */
61
+ export declare const useAutocompletion: (editor: Editor | null, config: AutocompletionConfig) => void;
62
+ //# sourceMappingURL=useAutocompletion.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useAutocompletion.d.ts","sourceRoot":"","sources":["../../../../../src/components/organisms/CodeArea/useAutocompletion.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AAGxC,MAAM,WAAW,gBAAgB;IAC/B,wCAAwC;IACxC,KAAK,EAAE,MAAM,CAAA;IACb,kDAAkD;IAClD,IAAI,EAAE,MAAM,CAAA;CACb;AAED,MAAM,WAAW,aAAa;IAC5B,kDAAkD;IAClD,MAAM,EAAE,MAAM,CAAA;IACd,6CAA6C;IAC7C,KAAK,EAAE,gBAAgB,EAAE,CAAA;CAC1B;AAED,MAAM,WAAW,oBAAoB;IACnC,sCAAsC;IACtC,QAAQ,EAAE,aAAa,EAAE,CAAA;CAC1B;AASD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,eAAO,MAAM,iBAAiB,WACpB,MAAM,GAAG,IAAI,UACb,oBAAoB,SAwF7B,CAAA"}
@@ -36,4 +36,11 @@ export declare function markInlineLinks(editor: Editor, className?: string): voi
36
36
  * @param className - CSS class to apply (defaults to 'cm-code-block')
37
37
  */
38
38
  export declare function markCodeBlocks(editor: Editor, className?: string): void;
39
+ /**
40
+ * Mark text preceded by a given symbol when at beginning of line or after space
41
+ * @param editor - CodeMirror editor instance
42
+ * @param symbol - The symbol to match (e.g., '@', '/', '$')
43
+ * @param className - CSS class to apply (defaults to 'cm-symbol-text')
44
+ */
45
+ export declare function markTextPrecededBySymbol(editor: Editor, symbol: string, className?: string): void;
39
46
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../../src/components/organisms/CodeArea/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAc,MAAM,YAAY,CAAA;AAEpD,wBAAgB,kCAAkC,CAAC,OAAO,EAAE,MAAM;UAEzC,MAAM;SAAO,MAAM;IA2B3C;AA4CD;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,EACf,OAAO,EAAE;IACP,SAAS,EAAE,MAAM,CAAA;IACjB,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CACvB,EACD,eAAe,CAAC,EAAE,MAAM,EAAE,GACzB,IAAI,CA4CN;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAC5B,MAAM,EAAE,MAAM,EACd,SAAS,SAAmB,GAC3B,IAAI,CAYN;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAC7B,MAAM,EAAE,MAAM,EACd,SAAS,SAAkB,GAC1B,IAAI,CAcN;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAC5B,MAAM,EAAE,MAAM,EACd,SAAS,SAAkB,GAC1B,IAAI,CAwBN"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../../src/components/organisms/CodeArea/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAc,MAAM,YAAY,CAAA;AAEpD,wBAAgB,kCAAkC,CAAC,OAAO,EAAE,MAAM;UAEzC,MAAM;SAAO,MAAM;IA2B3C;AA4CD;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,EACf,OAAO,EAAE;IACP,SAAS,EAAE,MAAM,CAAA;IACjB,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CACvB,EACD,eAAe,CAAC,EAAE,MAAM,EAAE,GACzB,IAAI,CA4CN;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAC5B,MAAM,EAAE,MAAM,EACd,SAAS,SAAmB,GAC3B,IAAI,CAYN;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAC7B,MAAM,EAAE,MAAM,EACd,SAAS,SAAkB,GAC1B,IAAI,CAcN;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAC5B,MAAM,EAAE,MAAM,EACd,SAAS,SAAkB,GAC1B,IAAI,CAwBN;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,SAAS,SAAmB,GAC3B,IAAI,CAsBN"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@carto/meridian-ds",
3
- "version": "2.4.0-structure.1",
3
+ "version": "2.5.0",
4
4
  "description": "CARTO Meridian Design System",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -68,6 +68,7 @@
68
68
  "chromatic": "^13.1.3",
69
69
  "codemirror": "^5.65.19",
70
70
  "date-fns": "^2.29.1",
71
+ "dompurify": "^3.2.6",
71
72
  "echarts": "5.6.0",
72
73
  "echarts-for-react": "3.0.2",
73
74
  "eslint": "8.57.0",
@@ -103,6 +104,7 @@
103
104
  "@mui/x-date-pickers": "^7.11.0",
104
105
  "cartocolor": "5.0.2",
105
106
  "codemirror": ">=5.65.19",
107
+ "dompurify": "^3.2.6",
106
108
  "echarts": ">=5.5.1",
107
109
  "echarts-for-react": ">=3.0.2",
108
110
  "react": ">=18.3.1",