rangy icon indicating copy to clipboard operation
rangy copied to clipboard

not working with npm and es6 import

Open poc7667 opened this issue 7 years ago • 7 comments

I installed the rangy by

Still could not find the module by import rangy from 'rangy';

Given the files seems installed.

.//node_modules/rangy
.//node_modules/rangy/lib/rangy-classapplier.js
.//node_modules/rangy/lib/rangy-core.js
.//node_modules/rangy/lib/rangy-highlighter.js
.//node_modules/rangy/lib/rangy-selectionsaverestore.js
.//node_modules/rangy/lib/rangy-serializer.js
.//node_modules/rangy/lib/rangy-textrange.js

poc7667 avatar Mar 18 '17 04:03 poc7667

+1 same problem here

olastor avatar Mar 19 '17 10:03 olastor

Try something like this

import rangy from 'rangy/lib/rangy-core.js';
import rangyHighlight from 'rangy/lib/rangy-highlighter';
import rangyClassApplier from 'rangy/lib/rangy-classapplier';
import rangyTextRange from 'rangy/lib/rangy-textrange';
import rangySerializer from 'rangy/lib/rangy-serializer';

LeCoupa avatar Mar 26 '17 12:03 LeCoupa

I found this syntax to be better:

import rangy from "rangy/lib/rangy-core.js"; import "rangy/lib/rangy-highlighter"; import "rangy/lib/rangy-classapplier"; import "rangy/lib/rangy-textrange"; import "rangy/lib/rangy-serializer";

..as then you can just use the rangy object for everything.

John-Williams avatar May 10 '18 07:05 John-Williams

@John-Williams @LeCoupa

I still get undefined for rangy. Are either of you using webpack or babel by chance?

nicholascloud avatar Nov 08 '18 17:11 nicholascloud

@nicholascloud I used the code from @John-Williams on a webpack setup and it all worked fine

import rangy from 'rangy'
import 'rangy/lib/rangy-classapplier'
import 'rangy/lib/rangy-highlighter'

function highlightSelection (userSelection) {
  rangy.init()
  let highlighter = rangy.createHighlighter()
  highlighter.addClassApplier(rangy.createClassApplier('mark', {
    ignoreWhiteSpace: true,
    tagNames: ['span', 'a']
  }))

  highlighter.highlightSelection('mark')
}
let selection = window.getSelection()
let rangeRepresentation = highlightSelection (selection.getRangeAt(0))

This wraps whatever the user has highlighted in a span with class mark

xmakina avatar Nov 20 '18 11:11 xmakina

Can anyone please help me import this under node_modules? I'm not able to find any example to use browserified rangy for firefox extension

0xrushi avatar Sep 27 '21 02:09 0xrushi

don't forget import 'rangy/lib/rangy-selectionsaverestore';

import rangy from "rangy/lib/rangy-core.js";
import "rangy/lib/rangy-highlighter";
import "rangy/lib/rangy-classapplier";
import "rangy/lib/rangy-textrange";
import "rangy/lib/rangy-serializer";
import 'rangy/lib/rangy-selectionsaverestore';

Pyot avatar Oct 22 '22 07:10 Pyot