Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
taufik-nurrohman committed Mar 11, 2024
1 parent 899d7d4 commit 459435d
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 60 deletions.
36 changes: 26 additions & 10 deletions .factory/index.html.pug
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ block content
button(onclick='editor.wrap(\'<i>\', \'</i>\');'): i I
= ' '
button(onclick='editor.insert(\'\', -1, true);') &#10084;
h2 Usage
h2#usage
a(href='#usage') #
= ' Usage'
h3 Browser
pre: code
| &lt;!DOCTYPE html&gt;
Expand Down Expand Up @@ -58,7 +60,9 @@ block content
| import TextEditor from '@taufik-nurrohman/text-editor';
|
| const editor = new TextEditor(document.querySelector('textarea'));
h2 Examples
h2#examples
a(href='#examples') #
= ' Examples'
ul
li: a(href='test.html' target='_blank') No Idea?
li: a(href='test/self.html' target='_blank') Multiple Instances
Expand All @@ -83,14 +87,18 @@ block content
li: a(href='test/trim.html' target='_blank') Trim Selection
li: a(href='test/self.input.html' target='_blank') Using #[code &lt;input&gt;] Instead of #[code &lt;textarea&gt;]
li: a(href='test/attach,detach.html' target='_blank') Attach, Detach
h2 Constructor
h2#constructor
a(href='#constructor') #
= ' Constructor'
pre: code const editor = new TextEditor(self, tab = '\t');
pre: code
| const editor = new TextEditor(self, state = {
| tab: '\t',
| with: []
| });
h2 Parameters
h2#parameters
a(href='#parameters') #
= ' Parameters'
h3: code self
p The text area element.
h3: code tab
Expand All @@ -101,7 +109,9 @@ block content
p The default indent character for #[code editor.pull()] and #[code editor.push()] method.
h3: code state.with
p List of callable functions or objects containing an #[code attach()] method to be invoked each time the application is initialized. A very simple “plugin” system.
h2 Methods
h2#methods
a(href='#methods') #
= ' Methods'
h3 Instance Methods
p Instance methods are methods that are available through the results of a #[code TextEditor] construct.
h4: code editor.attach(self, state)
Expand Down Expand Up @@ -231,7 +241,9 @@ block content
p Static methods are methods that are directly available on the #[code TextEditor] object.
h4: code TextEditor.esc(value)
p Escape regular expression&rsquo;s special characters.
h2 Properties
h2#properties
a(href='#properties') #
= ' Properties'
h3 Instance Properties
p Instance properties are properties that are available through the results of a #[code TextEditor] construct.
h4: code editor.hooks
Expand All @@ -254,9 +266,9 @@ block content
h4: code editor.value
p Proxy that passes to the #[code editor.self.value] property.
pre: code
| console.log(editor.value); // Get editor value
| console.log(editor.value); // Get text area value
pre: code
| editor.value = 'asdf'; // Set editor value
| editor.value = 'asdf'; // Set text area value
h3 Static Properties
p Static properties are properties that are directly available on the #[code TextEditor] object.
h4: code TextEditor.state
Expand All @@ -276,7 +288,9 @@ block content
| if (+major &lt; 3) { &hellip; }
h4: code TextEditor.x
p List of regular expression characters to be escaped.
h2 Extensions
h2#extensions
a(href='#extensions') #
= ' Extensions'
h3 Anatomy of an Extension
p Extension as a function:
pre: code
Expand Down Expand Up @@ -312,7 +326,9 @@ block content
li: a(aria-disabled='true') BBCode Editor
li: a(aria-disabled='true') HTML Editor
li: a(aria-disabled='true') Markdown Editor
h2 License
h2#license
a(href='#license') #
= ' License'
p Use it for free, pay if you get paid. So, you&rsquo;ve just benefited financially after using this project? It&rsquo;s a good idea to #[a(href='https://paypal.me/tatautaufik' target='_blank') share a little financial support] with this open source project too. Your support will motivate me to do any further development, as well as to provide voluntary support to overcome problems related to this project.
p Thank you! ❤️
footer
Expand Down
28 changes: 16 additions & 12 deletions .factory/index.js.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function TextEditor(self, state) {
return new TextEditor(self, state);
}

self['#TextEditor'] = hook($);
self['_' + TextEditor.name] = hook($);

return $.attach(self, fromStates({}, TextEditor.state, isInteger(state) || isString(state) ? {
tab: state
Expand All @@ -72,16 +72,16 @@ TextEditor.state = {
'with': []
};

TextEditor.S = function (a, b, c) {
let t = this,
d = c.slice(a, b);
t.after = c.slice(b);
t.before = c.slice(0, a);
t.end = b;
t.length = toCount(d);
t.start = a;
t.value = d;
t.toString = () => d;
TextEditor.S = function (start, end, value) {
let $ = this,
current = value.slice(start, end);
$.after = value.slice(end);
$.before = value.slice(0, start);
$.end = end;
$.length = toCount(current);
$.start = start;
$.value = current;
$.toString = () => current;
};

TextEditor.version = '%(version)';
Expand All @@ -92,7 +92,7 @@ let theValuePrevious;

function theEvent(e) {
let self = this,
$ = self['#TextEditor'],
$ = self['_' + TextEditor.name],
type = e.type,
value = theValue(self);
if (value !== theValuePrevious) {
Expand Down Expand Up @@ -405,4 +405,8 @@ Object.defineProperty($$, 'value', {
}
});

Object.defineProperty($$.constructor, 'name', {
value: 'TextEditor'
});

export default TextEditor;
20 changes: 10 additions & 10 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ <h1>Text Editor 4.1.0</h1>
<main>
<p><textarea spellcheck="false" style="display:block;width:100%;">Lorem ipsum dolor sit amet.</textarea></p>
<p role="group"><button onclick="editor.wrap('&lt;b&gt;', '&lt;/b&gt;');"><b>B</b></button> <button onclick="editor.wrap('&lt;i&gt;', '&lt;/i&gt;');"><i>I</i></button> <button onclick="editor.insert('❤', -1, true);">&#10084;</button></p>
<h2>Usage</h2>
<h2 id="usage"><a href="#usage">#</a> Usage</h2>
<h3>Browser</h3>
<pre><code>&lt;!DOCTYPE html&gt;
&lt;html dir="ltr"&gt;
Expand All @@ -45,7 +45,7 @@ <h4>ECMAScript</h4>
<pre><code>import TextEditor from '@taufik-nurrohman/text-editor';

const editor = new TextEditor(document.querySelector('textarea'));</code></pre>
<h2>Examples</h2>
<h2 id="examples"><a href="#examples">#</a> Examples</h2>
<ul>
<li><a href="test.html" target="_blank">No Idea?</a></li>
<li><a href="test/self.html" target="_blank">Multiple Instances</a></li>
Expand All @@ -71,13 +71,13 @@ <h2>Examples</h2>
<li><a href="test/self.input.html" target="_blank">Using <code>&lt;input&gt;</code> Instead of <code>&lt;textarea&gt;</code></a></li>
<li><a href="test/attach,detach.html" target="_blank">Attach, Detach</a></li>
</ul>
<h2>Constructor</h2>
<h2 id="constructor"><a href="#constructor">#</a> Constructor</h2>
<pre><code>const editor = new TextEditor(self, tab = '\t');</code></pre>
<pre><code>const editor = new TextEditor(self, state = {
tab: '\t',
with: []
});</code></pre>
<h2>Parameters</h2>
<h2 id="parameters"><a href="#parameters">#</a> Parameters</h2>
<h3><code>self</code></h3>
<p>The text area element.</p>
<h3><code>tab</code></h3>
Expand All @@ -88,7 +88,7 @@ <h3><code>state.tab</code></h3>
<p>The default indent character for <code>editor.pull()</code> and <code>editor.push()</code> method.</p>
<h3><code>state.with</code></h3>
<p>List of callable functions or objects containing an <code>attach()</code> method to be invoked each time the application is initialized. A very simple “plugin” system.</p>
<h2>Methods</h2>
<h2 id="methods"><a href="#methods">#</a> Methods</h2>
<h3>Instance Methods</h3>
<p>Instance methods are methods that are available through the results of a <code>TextEditor</code> construct.</p>
<h4><code>editor.attach(self, state)</code></h4>
Expand Down Expand Up @@ -199,7 +199,7 @@ <h3>Static Methods</h3>
<p>Static methods are methods that are directly available on the <code>TextEditor</code> object.</p>
<h4><code>TextEditor.esc(value)</code></h4>
<p>Escape regular expression&rsquo;s special characters.</p>
<h2>Properties</h2>
<h2 id="properties"><a href="#properties">#</a> Properties</h2>
<h3>Instance Properties</h3>
<p>Instance properties are properties that are available through the results of a <code>TextEditor</code> construct.</p>
<h4><code>editor.hooks</code></h4>
Expand All @@ -219,8 +219,8 @@ <h4><code>editor.state</code></h4>
<p>Return the application states if any.</p>
<h4><code>editor.value</code></h4>
<p>Proxy that passes to the <code>editor.self.value</code> property.</p>
<pre><code>console.log(editor.value); // Get editor value</code></pre>
<pre><code>editor.value = 'asdf'; // Set editor value</code></pre>
<pre><code>console.log(editor.value); // Get text area value</code></pre>
<pre><code>editor.value = 'asdf'; // Set text area value</code></pre>
<h3>Static Properties</h3>
<p>Static properties are properties that are directly available on the <code>TextEditor</code> object.</p>
<h4><code>TextEditor.state</code></h4>
Expand All @@ -238,7 +238,7 @@ <h4><code>TextEditor.version</code></h4>
if (+major &lt; 3) { &hellip; }</code></pre>
<h4><code>TextEditor.x</code></h4>
<p>List of regular expression characters to be escaped.</p>
<h2>Extensions</h2>
<h2 id="extensions"><a href="#extensions">#</a> Extensions</h2>
<h3>Anatomy of an Extension</h3>
<p>Extension as a function:</p>
<pre><code>function Extension(self, state = {}) {
Expand Down Expand Up @@ -271,7 +271,7 @@ <h3>List of Extensions</h3>
<li><a aria-disabled="true">HTML Editor</a></li>
<li><a aria-disabled="true">Markdown Editor</a></li>
</ul>
<h2>License</h2>
<h2 id="license"><a href="#license">#</a> License</h2>
<p>Use it for free, pay if you get paid. So, you&rsquo;ve just benefited financially after using this project? It&rsquo;s a good idea to <a href="https://paypal.me/tatautaufik" target="_blank">share a little financial support</a> with this open source project too. Your support will motivate me to do any further development, as well as to provide voluntary support to overcome problems related to this project.</p>
<p>Thank you! ❤️</p>
</main>
Expand Down
31 changes: 16 additions & 15 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,6 @@
if (isPattern(pattern)) {
return pattern;
}
// No need to escape `/` in the pattern string
pattern = pattern.replace(/\//g, '\\/');
return new RegExp(pattern, isSet(opt) ? opt : 'g');
};
var x = "!$^*()+=[]{}|:<>,.?/-";
Expand Down Expand Up @@ -232,7 +230,7 @@
if (!isInstance($, TextEditor)) {
return new TextEditor(self, state);
}
self['#TextEditor'] = hook($);
self['_' + TextEditor.name] = hook($);
return $.attach(self, fromStates({}, TextEditor.state, isInteger(state) || isString(state) ? {
tab: state
} : state || {}));
Expand All @@ -242,17 +240,17 @@
'tab': '\t',
'with': []
};
TextEditor.S = function (a, b, c) {
var t = this,
d = c.slice(a, b);
t.after = c.slice(b);
t.before = c.slice(0, a);
t.end = b;
t.length = toCount(d);
t.start = a;
t.value = d;
t.toString = function () {
return d;
TextEditor.S = function (start, end, value) {
var $ = this,
current = value.slice(start, end);
$.after = value.slice(end);
$.before = value.slice(0, start);
$.end = end;
$.length = toCount(current);
$.start = start;
$.value = current;
$.toString = function () {
return current;
};
};
TextEditor.version = '4.1.0';
Expand All @@ -261,7 +259,7 @@

function theEvent(e) {
var self = this,
$ = self['#TextEditor'],
$ = self['_' + TextEditor.name],
type = e.type,
value = theValue(self);
if (value !== theValuePrevious) {
Expand Down Expand Up @@ -608,5 +606,8 @@
this.self.value = value;
}
});
Object.defineProperty($$.constructor, 'name', {
value: 'TextEditor'
});
return TextEditor;
}));

0 comments on commit 459435d

Please sign in to comment.