-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmulti-one-instance.html
More file actions
243 lines (228 loc) · 9.55 KB
/
multi-one-instance.html
File metadata and controls
243 lines (228 loc) · 9.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset='UTF-8'>
<meta name='viewport' content='width=device-width, initial-scale=1.0'>
<title>Medium Editor - Single Instance Multiple Elements Demo</title>
<link rel='stylesheet' href='css/demo.css'>
<link rel='stylesheet' href='http://netdna.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.css'>
<link rel='stylesheet' href='../src/css/medium-editor.css'>
<link rel='stylesheet' href='../src/css/themes/default.css' id='medium-editor-theme'>
<style>
.demo-section {
margin-bottom: 2rem;
padding: 1.5rem;
border: 1px solid #e9ecef;
border-radius: 8px;
background: #fff;
}
.demo-section h3 {
margin-top: 0;
color: #495057;
display: flex;
align-items: center;
gap: 0.5rem;
}
.demo-description {
background: #f8f9fa;
border-left: 4px solid #007bff;
padding: 1rem;
margin: 1rem 0;
font-size: 14px;
line-height: 1.5;
}
.editable, .editable2 {
min-height: 150px;
border: 2px dashed #dee2e6;
border-radius: 6px;
padding: 1rem;
margin: 1rem 0;
transition: border-color 0.2s ease;
}
.editable:focus, .editable2:focus {
border-color: #007bff;
outline: none;
}
.editable2 {
border-color: #28a745;
background: #f8fff9;
}
.controls-section {
background: #f8f9fa;
border: 1px solid #dee2e6;
border-radius: 6px;
padding: 1rem;
margin-bottom: 2rem;
}
.controls-section h3 {
margin-top: 0;
}
.theme-selector {
display: flex;
align-items: center;
gap: 0.5rem;
margin: 1rem 0;
}
.theme-selector select {
padding: 0.5rem;
border: 1px solid #ced4da;
border-radius: 4px;
font-size: 14px;
}
.editor-info {
background: #e7f3ff;
border: 1px solid #b3d7ff;
border-radius: 4px;
padding: 0.75rem;
margin: 0.5rem 0;
font-size: 13px;
}
.editor-info strong {
color: #0066cc;
}
/* Shiki syntax highlighting styles */
.code-example {
background: #f8f9fa;
border: 1px solid #e9ecef;
border-radius: 4px;
padding: 1rem;
margin: 1rem 0;
font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
font-size: 12px;
overflow-x: auto;
line-height: 1.5;
}
.code-example.shiki-highlighted {
background: transparent;
padding: 0;
}
.code-example.shiki-highlighted code {
display: block;
padding: 1rem;
border-radius: 4px;
font-size: 12px;
line-height: 1.5;
overflow-x: auto;
}
.shiki {
background: #f8f9fa !important;
border: 1px solid #e9ecef;
border-radius: 4px;
}
.source-attribution {
text-align: center;
margin-top: 2rem;
font-size: 12px;
color: #6c757d;
}
</style>
</head>
<body>
<a href='https://github.com/stacksjs/ts-medium-editor' class='github-link' aria-label='Fork me on GitHub'>
<img style='z-index: 100;position: absolute; top: 0; right: 0; border: 0;'
src='https://s3.amazonaws.com/github/ribbons/forkme_right_gray_6d6d6d.png'
alt='Fork me on GitHub'>
</a>
<div class='controls-section'>
<h3>🎨 Theme Selector</h3>
<div class='theme-selector'>
<label for='sel-themes'>Choose Theme:</label>
<select id='sel-themes'>
<option value='themes/default' selected>default</option>
<option value='themes/roman'>roman</option>
<option value='themes/mani'>mani</option>
<option value='themes/flat'>flat</option>
<option value='themes/bootstrap'>bootstrap</option>
<option value='themes/tim'>tim</option>
<option value='themes/beagle'>beagle</option>
</select>
</div>
<p><em>Try different themes to see how they affect the editor appearance!</em></p>
</div>
<div id='container'>
<header>
<h1>Medium Editor - Single Instance Multiple Elements</h1>
<p>This demo shows how to dynamically add elements to an existing editor instance using <code>addElements()</code>.</p>
</header>
<section class='demo-section'>
<h3>📝 Initial Editor Element</h3>
<div class='demo-description'>
This element was included when the editor was first created with the <code>.editable</code> class selector.
</div>
<div class='editor-info'>
<strong>Status:</strong> Original element managed by the editor instance
</div>
<div class='editable'>
<p>My father's family name being <a href='https://en.wikipedia.org/wiki/Pip_(Great_Expectations)'>Pirrip</a>, and my Christian name Philip, my infant tongue could make of both names nothing longer or more explicit than Pip. So, I called myself Pip, and came to be called Pip.</p>
<p>I give Pirrip as my father's family name, on the authority of his tombstone and my sister,—Mrs. Joe Gargery, who married the blacksmith. As I never saw my father or my mother, and never saw any likeness of either of them (for their days were long before the days of photographs), my first fancies regarding what they were like were unreasonably derived from their tombstones.</p>
</div>
</section>
<section class='demo-section'>
<h3>➕ Dynamically Added Element</h3>
<div class='demo-description'>
This element was added to the same editor instance after initialization using <code>editor.addElements()</code>.
Notice how it shares the same toolbar and configuration as the first element.
</div>
<div class='editor-info'>
<strong>Status:</strong> Added dynamically with <code>addElements(document.querySelector('.editable2'))</code>
</div>
<div class='editable2'>
<p>This element was <strong>dynamically added</strong> to the existing editor instance. It shares the same toolbar configuration and behavior as the original element.</p>
<p>Ours was the marsh country, down by the river, within, as the river wound, twenty miles of the sea. My first most vivid and broad impression of the identity of things seems to me to have been gained on a memorable raw afternoon towards evening.</p>
</div>
</section>
<section class='demo-section'>
<h3>💻 Code Implementation</h3>
<div class='demo-description'>
Here's how to create an editor and dynamically add elements to it:
</div>
<h4>1. Create Initial Editor</h4>
<div class='code-example' data-lang='typescript'>const editor = new MediumEditor('.editable', {
buttonLabels: 'fontawesome',
toolbar: {
buttons: ['bold', 'italic', 'underline', 'anchor', 'h2', 'h3', 'quote'],
},
placeholder: {
text: 'Click here to edit...',
},
})</div>
<h4>2. Add Elements Dynamically</h4>
<div class='code-example' data-lang='typescript'>// Add second element to the same editor instance
const secondElement = document.querySelector('.editable2')
if (secondElement) {
editor.addElements(secondElement)
}</div>
<h4>3. Subscribe to Events</h4>
<div class='code-example' data-lang='typescript'>// Listen for input events across all elements
editor.subscribe('editableInput', (event, editable) => {
if (editable) {
// eslint-disable-next-line no-console
console.log('Content changed in:', editable.className)
}
})</div>
<h4>4. Theme Switching</h4>
<div class='code-example' data-lang='typescript'>const themeSelector = document.getElementById('sel-themes')
const cssLink = document.getElementById('medium-editor-theme')
themeSelector.addEventListener('change', function () {
cssLink.href = `../src/css/${this.value}.css`
})</div>
<h4>Key Features Demonstrated</h4>
<ul>
<li><strong>Dynamic Element Addition:</strong> Add elements to existing editor instances</li>
<li><strong>Shared Configuration:</strong> All elements share the same toolbar and settings</li>
<li><strong>Event Subscription:</strong> Listen for events across all managed elements</li>
<li><strong>Theme Switching:</strong> Change editor appearance dynamically</li>
<li><strong>FontAwesome Integration:</strong> Professional icon set for toolbar buttons</li>
</ul>
</section>
</div>
<div class='source-attribution'>
<small>
<a style='color: #6c757d;' target='_blank' href='http://www.goodreads.com/reader/475-great-expectations'>
Sample text from 'Great Expectations' by Charles Dickens
</a>
</small>
</div>
<script type='module' src='ts/multi-one-instance.ts'></script>
</body>
</html>