@elementor/editor-controls 3.33.0-97 → 3.33.0-98

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.d.mts CHANGED
@@ -317,7 +317,7 @@ declare const ControlFormLabel: (props: FormLabelProps) => React$1.JSX.Element;
317
317
 
318
318
  type CssEditorProps = {
319
319
  value: string;
320
- onChange: (value: string) => void;
320
+ onChange: (value: string, isValid: boolean) => void;
321
321
  };
322
322
  declare const CssEditor: ({ value, onChange }: CssEditorProps) => React$1.JSX.Element;
323
323
 
package/dist/index.d.ts CHANGED
@@ -317,7 +317,7 @@ declare const ControlFormLabel: (props: FormLabelProps) => React$1.JSX.Element;
317
317
 
318
318
  type CssEditorProps = {
319
319
  value: string;
320
- onChange: (value: string) => void;
320
+ onChange: (value: string, isValid: boolean) => void;
321
321
  };
322
322
  declare const CssEditor: ({ value, onChange }: CssEditorProps) => React$1.JSX.Element;
323
323
 
package/dist/index.js CHANGED
@@ -5333,8 +5333,15 @@ var EditorWrapper = (0, import_ui79.styled)(import_ui79.Box)`
5333
5333
  position: relative;
5334
5334
  height: 200px;
5335
5335
 
5336
- .monaco-editor .colorpicker-widget {
5337
- z-index: 99999999 !important;
5336
+ .monaco-editor .suggest-widget {
5337
+ width: 220px !important;
5338
+ max-width: 220px !important;
5339
+ }
5340
+
5341
+ .visual-content-dimmed {
5342
+ opacity: 0.6;
5343
+ color: #aaa !important;
5344
+ pointer-events: none;
5338
5345
  }
5339
5346
  `;
5340
5347
  var ResizeHandle = (0, import_ui79.styled)(import_ui79.Button)`
@@ -5425,6 +5432,16 @@ function validate(editor, monaco) {
5425
5432
  const allMarkers = monaco.editor.getModelMarkers({ resource: model.uri });
5426
5433
  return allMarkers.filter((marker) => marker.severity === monaco.MarkerSeverity.Error).length === 0;
5427
5434
  }
5435
+ function clearMarkersFromVisualContent(editor, monaco) {
5436
+ const model = editor.getModel();
5437
+ if (!model) {
5438
+ return;
5439
+ }
5440
+ const allMarkers = monaco.editor.getModelMarkers({ resource: model.uri });
5441
+ const filteredMarkers = allMarkers.filter((marker) => marker.startLineNumber !== 1);
5442
+ const nonCustomMarkers = filteredMarkers.filter((m) => m.source !== "custom-css-rules");
5443
+ monaco.editor.setModelMarkers(model, "css", nonCustomMarkers);
5444
+ }
5428
5445
 
5429
5446
  // src/components/css-code-editor/resize-handle.tsx
5430
5447
  var React91 = __toESM(require("react"));
@@ -5471,6 +5488,60 @@ var ResizeHandleComponent = ({ onResize, containerRef, onHeightChange }) => {
5471
5488
  );
5472
5489
  };
5473
5490
 
5491
+ // src/components/css-code-editor/visual-content-change-protection.ts
5492
+ var preventChangeOnVisualContent = (editor) => {
5493
+ const model = editor.getModel();
5494
+ if (!model) {
5495
+ return;
5496
+ }
5497
+ const decorationsCollection = editor.createDecorationsCollection();
5498
+ const applyVisualContentStyling = () => {
5499
+ const totalLines = model.getLineCount();
5500
+ const decorations = [];
5501
+ decorations.push({
5502
+ range: {
5503
+ startLineNumber: 1,
5504
+ startColumn: 1,
5505
+ endLineNumber: 1,
5506
+ endColumn: model.getLineContent(1).length + 1
5507
+ },
5508
+ options: {
5509
+ inlineClassName: "visual-content-dimmed",
5510
+ isWholeLine: false
5511
+ }
5512
+ });
5513
+ if (totalLines > 1) {
5514
+ decorations.push({
5515
+ range: {
5516
+ startLineNumber: totalLines,
5517
+ startColumn: 1,
5518
+ endLineNumber: totalLines,
5519
+ endColumn: model.getLineContent(totalLines).length + 1
5520
+ },
5521
+ options: {
5522
+ inlineClassName: "visual-content-dimmed",
5523
+ isWholeLine: false
5524
+ }
5525
+ });
5526
+ }
5527
+ decorationsCollection.set(decorations);
5528
+ };
5529
+ applyVisualContentStyling();
5530
+ model.onDidChangeContent(() => {
5531
+ applyVisualContentStyling();
5532
+ });
5533
+ const originalPushEditOperations = model.pushEditOperations;
5534
+ model.pushEditOperations = function(beforeCursorState, editOperations, cursorStateComputer) {
5535
+ const totalLines = model.getLineCount();
5536
+ const filteredOperations = editOperations.filter((operation) => {
5537
+ const range = operation.range;
5538
+ const affectsProtectedLine = range.startLineNumber === 1 || range.endLineNumber === 1 || range.startLineNumber === totalLines || range.endLineNumber === totalLines;
5539
+ return !affectsProtectedLine;
5540
+ });
5541
+ return originalPushEditOperations.call(this, beforeCursorState, filteredOperations, cursorStateComputer);
5542
+ };
5543
+ };
5544
+
5474
5545
  // src/components/css-code-editor/css-editor.tsx
5475
5546
  var setVisualContent = (value) => {
5476
5547
  const trimmed = value.trim();
@@ -5484,44 +5555,16 @@ var getActual = (value) => {
5484
5555
  }
5485
5556
  return lines.slice(1, -1).map((line) => line.replace(/^ {2}/, "")).join("\n");
5486
5557
  };
5487
- var preventChangeOnVisualContent = (editor, monaco) => {
5488
- const model = editor.getModel();
5489
- if (!model) {
5490
- return;
5491
- }
5492
- editor.onKeyDown((e) => {
5493
- const position = editor.getPosition();
5494
- if (!position) {
5495
- return;
5496
- }
5497
- const totalLines = model.getLineCount();
5498
- const isInProtectedRange = position.lineNumber === 1 || position.lineNumber === totalLines;
5499
- if (isInProtectedRange) {
5500
- const allowedKeys = [
5501
- monaco.KeyCode.UpArrow,
5502
- monaco.KeyCode.DownArrow,
5503
- monaco.KeyCode.LeftArrow,
5504
- monaco.KeyCode.RightArrow,
5505
- monaco.KeyCode.Home,
5506
- monaco.KeyCode.End,
5507
- monaco.KeyCode.PageUp,
5508
- monaco.KeyCode.PageDown,
5509
- monaco.KeyCode.Tab,
5510
- monaco.KeyCode.Escape
5511
- ];
5512
- if (!allowedKeys.includes(e.keyCode)) {
5513
- e.preventDefault();
5514
- e.stopPropagation();
5515
- }
5516
- }
5517
- });
5518
- };
5519
5558
  var createEditorDidMountHandler = (editorRef, monacoRef, debounceTimer, onChange) => {
5520
5559
  return (editor, monaco) => {
5521
5560
  editorRef.current = editor;
5522
5561
  monacoRef.current = monaco;
5523
- preventChangeOnVisualContent(editor, monaco);
5562
+ preventChangeOnVisualContent(editor);
5524
5563
  setCustomSyntaxRules(editor, monaco);
5564
+ monaco.editor.onDidChangeMarkers(() => {
5565
+ setTimeout(() => clearMarkersFromVisualContent(editor, monaco), 0);
5566
+ });
5567
+ editor.setPosition({ lineNumber: 2, column: (editor.getModel()?.getLineContent(2).length ?? 0) + 1 });
5525
5568
  editor.onDidChangeModelContent(() => {
5526
5569
  const code = editor.getModel()?.getValue() ?? "";
5527
5570
  const userContent = getActual(code);
@@ -5535,9 +5578,7 @@ var createEditorDidMountHandler = (editorRef, monacoRef, debounceTimer, onChange
5535
5578
  return;
5536
5579
  }
5537
5580
  const hasNoErrors = validate(editorRef.current, monacoRef.current);
5538
- if (hasNoErrors) {
5539
- onChange(userContent);
5540
- }
5581
+ onChange(userContent, hasNoErrors);
5541
5582
  }, 500);
5542
5583
  debounceTimer.current = newTimer;
5543
5584
  });
@@ -5575,18 +5616,23 @@ var CssEditor = ({ value, onChange }) => {
5575
5616
  height: "100%",
5576
5617
  language: "css",
5577
5618
  theme: theme.palette.mode === "dark" ? "vs-dark" : "vs",
5578
- defaultValue: setVisualContent(value),
5619
+ value: setVisualContent(value),
5579
5620
  onMount: handleEditorDidMount,
5580
5621
  options: {
5581
- lineNumbers: "off",
5582
- folding: false,
5583
- showFoldingControls: "never",
5622
+ lineNumbers: "on",
5623
+ folding: true,
5584
5624
  minimap: { enabled: false },
5585
5625
  fontFamily: "Roboto, Arial, Helvetica, Verdana, sans-serif",
5586
5626
  fontSize: 12,
5587
5627
  renderLineHighlight: "none",
5588
5628
  hideCursorInOverviewRuler: true,
5589
- fixedOverflowWidgets: true
5629
+ fixedOverflowWidgets: true,
5630
+ suggestFontSize: 10,
5631
+ suggestLineHeight: 14,
5632
+ stickyScroll: {
5633
+ enabled: false
5634
+ },
5635
+ lineDecorationsWidth: 2
5590
5636
  }
5591
5637
  }
5592
5638
  ), /* @__PURE__ */ React92.createElement(