Skip to content

A platform for community discussion. Free, open, simple.

17.5 KB
Raw Blame
@use "lib/viewport";

.ProseMirror-container {
  margin: 0;
  overscroll-behavior: contain;
  overflow-anchor: none;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  height: 100%;
}

.ProseMirror {
  outline: 0;
  padding: 0 0.625rem;

  > div:first-child,
  > details:first-child {
    margin-top: var(--space-4);

    // This is hacky, but helps having the leading gapcursor at the right position
    &.ProseMirror-gapcursor {
      position: relative;
      display: block;
    }
  }

  h1,
  h2,
  h3,
  h4,
  h5,
  h6 {
    margin: 30px 0 10px;

    &:first-child {
      margin-top: 10px;
    }
  }

  h1 {
    font-size: var(--font-up-3-rem);
  }

  h2 {
    font-size: var(--font-up-2-rem);
  }

  h3 {
    font-size: var(--font-up-1-rem);
  }

  .upload-placeholder {
    &.--image {
      position: relative;
      display: inline-block;
      vertical-align: bottom;

      img {
        max-width: 350px;

        @include viewport.until(sm) {
          max-width: 100%;
        }
        height: auto;
        border-radius: var(--d-border-radius);
        display: block;
        animation: placeholder 1.5s infinite;
      }
    }

    &.--file {
      display: inline-flex;
      align-items: center;
      gap: var(--space-2);
      padding: 0 var(--space-1) 0 0.65em;
      border: 1px solid var(--primary-low-mid);
      border-radius: var(--d-border-radius);
      color: var(--primary-high);
      font-size: var(--font-down-1-rem);

      .d-icon {
        fill: currentcolor;
      }
    }

    &__overlay {
      position: absolute;
      bottom: var(--space-2);
      right: var(--space-2);
      display: flex;
      align-items: center;
      gap: var(--space-2);
      padding: 0 var(--space-1) 0 0.65em;
      background: var(--primary-very-low);
      border: 1px solid var(--primary-low-mid);
      border-radius: var(--d-border-radius);
      color: var(--primary-high);
      font-size: var(--font-down-1-rem);
    }

    &__progress {
      color: var(--tertiary);
      font-weight: bold;
    }

    &__filename,
    &__icon {
      animation: placeholder 1.5s infinite;
    }

    &__cancel {
      padding: 0.5em 0.65em;
    }
  }

  @keyframes placeholder {
    0% {
      opacity: 0.6;
    }

    50% {
      opacity: 0.4;
    }

    100% {
      opacity: 0.6;
    }
  }

  ul,
  ol {
    padding-left: 1.25em;

    &[data-tight="true"] > li > p {
      margin-top: 0;
      margin-bottom: 0;
    }
  }

  p {
    line-height: 1.5;

    &:first-child {
      margin-top: 0.59rem;
    }
  }

  p[data-placeholder] {
    overflow: hidden;

    &::before {
      pointer-events: none;
      position: absolute;
      padding-top: 2px;
      padding-right: 0.5rem;
      content: attr(data-placeholder);
      color: var(--primary-400);
      line-height: 1.1;
    }
  }

  del {
    background-color: var(--danger-low);
  }

  ins {
    background-color: var(--success-low);
  }

  mark {
    background-color: var(--highlight);
  }

  td {
    padding: 3px 3px 3px 0.5em;
  }

  th {
    padding-bottom: 2px;
    font-weight: bold;
    color: var(--primary);
  }

  a:not([contenteditable="false"] a) {
    cursor: inherit;
  }

  kbd {
    // I believe this shouldn't be `inline-flex` in posts either (test with emojis before/after text to see why),
    // but overriding just for the editor for now
    display: inline;
    padding-top: 0.2rem;
  }

  .onebox-wrapper {
    white-space: normal;
  }

  .code-language-select {
    position: absolute;
    right: 0.25rem;
    top: -0.6rem;
    border: 1px solid var(--content-border-color);
    border-radius: var(--d-border-radius);
    background-color: var(--primary-very-low);
    color: var(--primary-medium);
    font-size: var(--font-down-1-rem);
  }

  pre {
    position: relative;
  }

  .html-block {
    border: 2px dashed var(--primary-low-mid);
    border-radius: var(--d-border-radius);

    &.ProseMirror-selectednode {
      outline-offset: -2px;
      border-radius: calc(var(--d-border-radius) + 2px);
    }

    &::after {
      position: absolute;
      right: 0;
      top: 0;
      content: "HTML";
      font-size: var(--font-down-2-rem);
      color: var(--primary-medium);
      z-index: 1;
      background: var(--secondary-very-high);
      padding: 0 var(--space-1);
      border-bottom-left-radius: var(--d-border-radius);
      border-top-right-radius: var(--d-border-radius);
    }
  }

  .composer-image-grid {
    position: relative;

    // Portal whitespace should not create anonymous line boxes in the grid.
    display: flex;
    flex-direction: column;
    min-block-size: var(--composer-image-grid-controls-min-block-size, 0);
    border: 2px dashed var(--primary-low-mid);
    border-radius: var(--d-border-radius);
    padding: var(--space-half) var(--space-2) 0 var(--space-2);
    margin-block: var(--space-4);

    &__content {
      display: flex;
      flex-wrap: wrap;
      gap: var(--space-2);
      padding-block: var(--space-2);

      p {
        margin: 0;
      }
    }

    &__remove-btn {
      color: var(--primary-medium);
      padding: var(--space-1) var(--space-2);
      background: var(--secondary);
      border: 0;
      border-radius: var(--d-border-radius);
      font-size: var(--font-down-1-rem);
      white-space: nowrap;
      display: flex;
      align-items: center;
      gap: var(--space-1);
      cursor: pointer;

      @include viewport.until(sm) {
        padding: var(--space-2) var(--space-4);
      }

      html.discourse-no-touch &:hover:not(:disabled) {
        color: var(--primary);
        background: var(--d-hover);
      }

      &:active:not(:disabled) {
        background: var(--secondary);
      }

      &:focus-visible {
        @include default-focus;
      }
    }

    img:not(.ProseMirror-separator) {
      @include viewport.until(md) {
        width: 150px !important;
        height: 150px !important;
      }

      @include viewport.from(md) {
        width: 200px !important;
        height: 200px !important;
      }
      object-fit: cover;
    }

    &.ProseMirror-selectednode {
      outline-offset: -2px;
      border-radius: calc(var(--d-border-radius) + 2px);
    }
  }

  .composer-html-inline-node {
    outline: 1px dashed var(--primary-low-mid);
    padding-inline: 1px;
    border-radius: 2px;
  }

  .composer-wrap-node {
    position: relative;
    white-space: normal;
    border: 2px dashed var(--primary-low-mid);
    border-radius: var(--d-border-radius);
    padding-inline: var(--space-2);
    margin-block: var(--space-4);

    &.ProseMirror-selectednode {
      outline-offset: -2px;
      border-radius: calc(var(--d-border-radius) + 2px);
    }

    .d-wrap-indicator {
      color: var(--primary-medium);
      background-color: var(--secondary);
      border: none;
      cursor: pointer;

      &:hover {
        color: var(--primary);
      }

      &.--inline {
        font-size: var(--font-down-2);
        padding: var(--space-half) 0;
        margin-left: calc(-1 * var(--space-1));
        margin-right: var(--space-2);
        vertical-align: text-top;
        display: inline-block;
      }

      &.--block {
        position: absolute;
        z-index: 1;
        font-size: var(--font-down-1);
        left: var(--space-2);
        top: calc(-1 * var(--space-3) + 1px);
        padding: 0 var(--space-1);
      }
    }
  }

  // both faces share one grid cell, so swapping them does not move the document
  .composer-preview-node {
    position: relative;
    display: grid;
    border: 1px solid var(--primary-low);
    border-radius: var(--d-border-radius);
    margin-block: var(--space-4);
    overflow: hidden;

    > * {
      grid-area: 1 / 1;

      // a face fits the block and scrolls its own overflow, rather than
      // sizing the shared cell to fit its content
      min-width: 0;
      min-height: 0;
    }

    &.ProseMirror-selectednode {
      outline: 2px solid var(--tertiary);
      outline-offset: 2px;
    }

    // hidden, but still holding its space. `&` is a complex selector here, so
    // the hidden face is named in full rather than suffixed onto a second `&`
    &:not(.--source) .composer-preview-node__source,
    &.--source .composer-preview-node__preview {
      visibility: hidden;
    }

    // a long source scrolls within a bounded face instead of growing the block.
    // A preview that frames itself overrides the bound to match that frame.
    &__source {
      max-height: var(--composer-preview-node-source-max-height, 14lh);
    }

    &__source pre {
      margin: 0;
      height: 100%;
      overflow: auto;

      // the code element paints the backdrop, so it must fill the taller face's row
      code {
        box-sizing: border-box;
        min-height: 100%;
        max-height: none;
      }
    }

    &__preview {
      user-select: none;
      cursor: pointer;

      // the editor's display rules would otherwise override a renderer's [hidden]
      [hidden] {
        display: none;
      }
    }
  }

  .onebox-loading {
    border-radius: var(--d-border-radius);
    padding: 0 0.125rem;
    background: linear-gradient(
      90deg,
      var(--primary-very-low) 0%,
      var(--primary-low) 50%,
      var(--primary-very-low) 100%
    );
    background-size: 200% 100%;
    animation: loading-pulse 1.5s ease-in-out infinite;
  }

  @keyframes loading-pulse {
    0% {
      background-position: 200% 0;
    }

    100% {
      background-position: -200% 0;
    }
  }
}

.fk-d-menu[data-identifier="composer-link-toolbar"],
.fk-d-menu[data-identifier="composer-image-toolbar"],
.fk-d-menu[data-identifier="composer-image-alt-text"],
.fk-d-menu[data-identifier^="composer-image-grid-mode-"],
.fk-d-menu[data-identifier^="composer-image-grid-remove-"],
.fk-d-menu[data-identifier="composer-preview-toolbar"],
.fk-d-menu[data-identifier="composer-onebox-toolbar"] {
  user-select: none;
  z-index: z("composer", "dropdown");

  .fk-d-menu__inner-content {
    overflow: visible;
  }

  .toolbar__button {
    background-color: var(--secondary);
    color: var(--primary-medium);
    border-radius: var(--d-border-radius);

    .d-icon {
      color: var(--primary-medium);
    }

    &:hover:not(:disabled) {
      color: var(--primary);

      .d-icon {
        color: var(--primary);
      }
    }

    &:active {
      background: var(--secondary);
    }

    &:focus-visible {
      @include default-focus;
    }

    &.--active {
      background: var(--d-selected);
      color: var(--d-selected-text-color);
    }
  }

  .composer-link-toolbar__visit {
    .d-button-label {
      max-width: 12rem;
    }
  }
}

.composer-link-toolbar__visit {
  min-width: 0;
  align-items: center;

  // visit link has a right-side icon
  flex-direction: row-reverse;

  .d-icon {
    // overrides the default from d-button.scss
    margin-right: 0;
  }

  .d-button-label {
    font-size: var(--font-down-1-rem);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  &:not(:disabled) .d-button-label {
    margin-right: 0.5rem;
  }
}

.fk-d-menu[data-identifier="composer-image-alt-text"] {
  width: calc(100% - 1rem);
  min-width: calc(max(100% - 1rem, 7.25rem));
  background-color: rgb(var(--secondary-rgb), 0.65);
  backdrop-filter: blur(4px);
  color: var(--primary);
  isolation: auto;
  border-radius: var(--d-border-radius);
  font-size: var(--font-down-1);
  box-shadow: var(--shadow-dropdown);

  .fk-d-menu__inner-content {
    width: 100%;
    box-sizing: border-box;
    border: none;
    box-shadow: none;
    background-color: transparent;
    min-width: 100%;
    padding: 0.25rem 0.5rem;
  }

  &:focus-within {
    box-shadow: 0 0 0 2px var(--tertiary-high);
  }

  &:has(.image-alt-text-input.--expanded) {
    min-width: calc(max(100% - 1rem, 15rem));
  }
  transition: min-width 0.15s ease;
}

.composer-image-node {
  display: inline-block;
  white-space: normal;
  position: relative;

  // This makes the editor less pixel perfect with cooked, but it helps with some
  // hard positions (like between images), and makes the blinking cursor more visible
  // The vertical offset increases the drop area between image paragraphs
  margin: -2px 1px;
  padding: 2px 1px;

  img {
    display: inline-block;
    height: auto;
    max-width: 100%;
    border-radius: var(--d-border-radius);
    transition:
      width 0.2s ease,
      height 0.2s ease;

    &:not(.ProseMirror-selectednode):hover {
      cursor: pointer;
    }

    &.ProseMirror-selectednode {
      user-select: none;
      cursor: zoom-in;
    }
  }

  &:has(.image-alt-text-input:focus-within) img.ProseMirror-selectednode {
    cursor: default;
  }
}

.composer-video-node {
  aspect-ratio: 16 / 9;
  background-color: rgb(var(--always-black-rgb));
  border-radius: var(--d-border-radius);
  display: grid;
  overflow: hidden;
  place-items: center;
  position: relative;
  width: 100%;

  &__error {
    background-color: var(--danger-low);
    color: var(--primary);
    inset-block-start: 0;
    inset-inline: 0;
    padding: var(--space-2);
    position: absolute;
    z-index: 1;
  }

  &__play.btn-flat {
    --d-button-flat-bg-color: color-mix(
      in srgb,
      var(--primary) 75%,
      transparent
    );
    --d-button-flat-bg-color--focus: color-mix(
      in srgb,
      var(--primary) 85%,
      transparent
    );
    --d-button-flat-bg-color--hover: color-mix(
      in srgb,
      var(--primary) 85%,
      transparent
    );
    --d-button-flat-icon-color: var(--secondary);
    --d-button-flat-icon-color--hover: var(--secondary);
    padding: 1rem;
    z-index: 2;

    .d-icon {
      filter: drop-shadow(3px 3px 2px rgb(var(--always-black-rgb), 0.25));
      height: 2.3rem;
      transition: transform 0.15s;
      width: 2.3rem;

      @media (prefers-reduced-motion) {
        transition: transform 0s;
      }
    }

    @include hover {
      .d-icon {
        transform: scale(1.2);
      }
    }
  }

  &__video {
    display: block;
    height: 100%;
    border-radius: var(--d-border-radius);
    inset: 0;
    object-fit: contain;
    position: absolute;
    width: 100%;

    &.is-inactive {
      pointer-events: none;
    }
  }
}

.image-alt-text-input {
  min-width: 100%;
  display: flex;
  position: relative;
  transition: height 0.15s ease;
  height: 1.5em;

  @media (prefers-reduced-motion: reduce) {
    transition: none;
  }

  &.--expanded {
    height: 4.25em;
  }

  &__field {
    flex: 1;
    border: none;
    outline: none;
    padding: 0;
    background: transparent;
    resize: none;
    margin: 0;
    scrollbar-color: rgb(var(--primary-rgb), 0.3) transparent;
    scrollbar-width: thin;
    overflow-y: auto;
    scrollbar-gutter: stable;
    line-height: var(--line-height-large);

    &::placeholder {
      color: var(--primary);
    }

    &:focus {
      outline: none;
    }
  }

  &__display {
    cursor: pointer;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
  }
}

/*********************************************************
 Section below from prosemirror-view/style/prosemirror.css
 ********************************************************/

// stylelint-disable-next-line no-duplicate-selectors
.ProseMirror {
  overflow-wrap: break-word;
  white-space: break-spaces;

  // Any children with position fixed will be relative to this element (eg. footnotes)
  // see https://developer.mozilla.org/en-US/docs/Web/CSS/Guides/Display/Containing_block#identifying_the_containing_block
  contain: layout;
}

// stylelint-disable-next-line no-duplicate-selectors
.ProseMirror pre {
  white-space: pre-wrap;
}

.ProseMirror li {
  position: relative;
}

.ProseMirror-hideselection *::selection {
  background: transparent;
}

.ProseMirror-hideselection {
  caret-color: transparent;
}

/* See https://github.com/ProseMirror/prosemirror/issues/1421#issuecomment-1759320191 */
.ProseMirror [draggable][contenteditable="false"] {
  user-select: text;
}

.ProseMirror-selectednode {
  outline: 2px solid var(--tertiary-high);
  border-radius: var(--d-border-radius);
}

/* Make sure li selections wrap around markers */
li.ProseMirror-selectednode {
  outline: none;
}

li.ProseMirror-selectednode::after {
  content: "";
  position: absolute;
  left: -32px;
  right: -2px;
  top: -2px;
  bottom: -2px;
  border: 2px solid var(--tertiary-high);
  border-radius: var(--d-border-radius);
  pointer-events: none;
}

/* Protect against generic img rules */
.ProseMirror-separator {
  display: inline !important;
  border: none !important;
  margin: 0 !important;
}

/************************************************************
 Section below from prosemirror-gapcursor/style/gapcursor.css
 ***********************************************************/

.ProseMirror-gapcursor {
  display: none;
  pointer-events: none;
  position: sticky;
}

.ProseMirror-gapcursor::after {
  content: "";
  display: block;
  position: absolute;
  top: -2px;
  width: 20px;
  border-top: 1px solid var(--primary);
  animation: ProseMirror-cursor-blink 1.1s steps(2, start) infinite;
}

@keyframes ProseMirror-cursor-blink {
  to {
    visibility: hidden;
  }
}

.ProseMirror-focused .ProseMirror-gapcursor {
  display: block;
}

/************************************************************
 Section below from prosemirror-codemark/src/codemark.css
 ***********************************************************/
@keyframes fake-cursor-blink {
  49% {
    border-color: unset;
  }

  50% {
    border-color: transparent;
  }

  99% {
    border-color: transparent;
  }
}

.no-cursor {
  caret-color: transparent;
}

div:focus .fake-cursor,
span:focus .fake-cursor {
  margin-right: -1px;
  border-left-width: 1px;
  border-left-style: solid;
  animation: fake-cursor-blink 1s;
  animation-iteration-count: infinite;
  position: relative;
  z-index: 1;
}