Beispiel #1
0
 this.clipboard.addMatcher(Node.TEXT_NODE, function(node, delta) {
   let index = 0;
   const regex = /https?:\/\/[^\s]+/g;
   let match = null;
   const composer = new Delta();
   // eslint-disable-next-line no-cond-assign
   while ((match = regex.exec(node.data))) {
     composer.retain(match.index - index);
     index = regex.lastIndex;
     composer.retain(match[0].length, { link: match[0] });
   }
   return delta.compose(composer);
 });
Beispiel #2
0
  /**
   * 이미지그리드에서 이미지를 제거 (only remove, move from image-grid to image-grid, move from image-grid to block(text));
   * @param {Object} originBlot 사용자가 드래그를 시작한 이미지가 들어있는 blot. 항상 'image-grid'이다.
   * @param {Number} originIndexInBlot 드래그한 이미지가 소속되어있던 그리드 내에서 해당 이미지가 가지는 인덱스.
   * @param {Object} targetBlot 드롭한 타겟 blot. 'image-grid'이거나 'block'(일반 텍스트)이다. (없는 경우도 있음: 키보드의 backspace 혹은 delete를 통해 그리드 내에서 이미지를 지우는 경우)
   * @param {Number} targetIndexInBlot 드롭한 타겟이 'image-grid' blot일 경우 이미지가 들어갈 index
   */
  removeImageFromImageGrid(originBlot, originIndexInBlot, targetBlot, targetIndexInBlot) {
    const prevOriginData = this.getDataFromImageGridBlot(originBlot);
    const nextOriginData = [...prevOriginData];
    const [removedItem] = nextOriginData.splice(originIndexInBlot, 1);

    const originBlotIndex = this.quill.getIndex(originBlot);
    const updateDelta = new Delta();
    if (nextOriginData.length === 1) { // nextOriginData is image
      const nextOriginOps = this.makeOperations(nextOriginData);
      updateDelta
        .retain(originBlotIndex)
        .delete(1)
        .insert(...nextOriginOps);
      this.quill.updateContents(updateDelta, 'user');
    } else {
      this.quill.formatText(
        originBlotIndex,
        1,
        'remove-data',
        {
          index: originIndexInBlot,
          data: nextOriginData,
        },
        'user',
      );
    }

    if (removedItem && targetBlot) {
      const targetIndex = this.quill.getIndex(targetBlot);
      const { image, attributes } = removedItem;

      if (targetBlot.statics.blotName === 'image-grid') {
        if (targetIndexInBlot === -1) {
          this.insertImageToPrevLine(removedItem, targetBlot);
          return;
        }
        const prevTargetData = this.getDataFromImageGridBlot(targetBlot);
        const nextTargetData = [...prevTargetData];
        nextTargetData.splice(targetIndexInBlot, 0, removedItem);

        this.quill.formatText(
          targetIndex,
          1,
          'add-data',
          {
            index: targetIndexInBlot,
            data: nextTargetData,
          },
          'user',
        );
      } else {
        const newAttributes = _.cloneDeep(attributes);
        newAttributes['create-animation'] = 'fade-in-and-scale-up';
        const imageInsertDelta = new Delta()
          .retain(targetIndex)
          .insert({ image }, newAttributes);
        this.quill.updateContents(imageInsertDelta, 'user');
      }
    }
  }