@innovastudio/contentbox 1.4.19 → 1.4.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -39,6 +39,12 @@ Then import into your project:
39
39
  import ContentBox from '@innovastudio/contentbox';
40
40
  ```
41
41
 
42
+ ### Asset Files
43
+
44
+ Asset files (eg. template or snippet files) are also needed to run the ContentBox. They are located in the **assets** folder in the package.
45
+
46
+ **Note**: location of asset related files are flexible and can be configured. For example, you can move the asset files on different server (eg. CDN server).
47
+
42
48
  ## Additional Includes for Viewing Content
43
49
 
44
50
  For viewing content, additional includes are also needed.
@@ -114,6 +120,8 @@ ContentBox.js is written in pure Javascript (ES6) so you can use it in most situ
114
120
 
115
121
  React and Vue project examples are provided in separate downloads in the user area.
116
122
 
123
+ To run the HTML example, open using your browser: **public/example.html** from localhost or from your server.
124
+
117
125
  ## Folder Structure
118
126
 
119
127
  - public/
@@ -137,7 +145,7 @@ React and Vue project examples are provided in separate downloads in the user ar
137
145
  - ...
138
146
 
139
147
 
140
- ## Predesigned Sections (Templates)
148
+ ## Templates (Predesigned Sections)
141
149
 
142
150
  To start building a page, you can click the (+) button on the top left sidebar. This will open a selection of predesigned sections that you can add into your page.
143
151
 
@@ -145,21 +153,68 @@ To start building a page, you can click the (+) button on the top left sidebar.
145
153
 
146
154
  ![Quick Start](docs/predesigned-sections2.png)
147
155
 
148
- There are 2 predesigned section categories:
156
+ ![All Categories](docs/section-categories.png)
157
+
158
+ If you click **ALL CATEGORIES**, 2 sets of templates will be displayed:
159
+
149
160
  - Simple Start (to start from a basic/clean design)
150
161
  - Quick Start (to start with examples)
151
162
 
152
- The predesigned section files are located in the folder:
163
+ These 2 set of templates are located in the folder:
153
164
 
154
- **assets/designs/**
165
+ - **assets/simplestart/**
166
+ - **assets/quickstart/**
155
167
 
156
- It contains:
157
- - basic.js (a JSON file containing a list of simple designs)
158
- - examples.js (a JSON file containing a list of ready made designs)
159
- - images (contains assets for the designs)
160
- - preview (contains design thumbnails)
168
+ Each folder contains:
169
+
170
+ - templates.js (a JSON file containing a list of ready made designs)
171
+ - images/ (contains assets for the designs)
172
+ - preview/ (contains design thumbnails)
173
+
174
+ The templates are loaded using the following configuration:
161
175
 
162
- You can configure the file location by setting the **designUrl1**, **designUrl2** and **designPath** parameters:
176
+ ```javascript
177
+ const builder = new ContentBox({
178
+ wrapper: '.is-wrapper',
179
+ templates: [
180
+ {
181
+ url: 'assets/simplestart/templates.js',
182
+ path: 'assets/simplestart/',
183
+ pathReplace: [ ]
184
+ },
185
+ {
186
+ url: 'assets/quickstart/templates.js',
187
+ path: 'assets/quickstart/',
188
+ pathReplace: [ ]
189
+ },
190
+ ],
191
+ });
192
+ ```
193
+ Using the **templates** parameter, you can configure the template file (**url**), the asset location (**path**), and optionally, use **pathReplace** property to replace string found on the template file.
194
+
195
+ Here is an example of a different assets location:
196
+
197
+ ```javascript
198
+ const builder = new ContentBox({
199
+ wrapper: '.is-wrapper',
200
+ templates: [
201
+ {
202
+ url: 'https://path-to/assets/simplestart/templates.js',
203
+ path: 'https://path-to/assets/simplestart/',
204
+ pathReplace: [ ]
205
+ },
206
+ {
207
+ url: 'https://path-to/assets/quickstart/templates.js',
208
+ path: 'https://path-to/assets/quickstart/',
209
+ pathReplace: [ ]
210
+ },
211
+ ],
212
+ });
213
+ ```
214
+
215
+ #### For old version of ContentBox
216
+
217
+ In the old ContentBox, you can configure the template location by setting the **designUrl1**, **designUrl2** and **designPath** parameters. These still work. Note that in the old version, templates are located in **assets/designs/** folder.
163
218
 
164
219
  ```javascript
165
220
  const builder = new ContentBox({
@@ -186,6 +241,195 @@ In this example, the default location is changed to https://path-to/assets/desig
186
241
 
187
242
  With this, you can place all the assets in a separate server or different host (e.g. from a CDN).
188
243
 
244
+ ### Template Files
245
+
246
+ Let’s see one of the template file, the Simple Start template: assets/simplestart/templates.js.
247
+
248
+ ```javascript
249
+ var data_templates = {
250
+ name: 'Simple Start',
251
+ categories: [
252
+ { id: 1, name: 'Basic' },
253
+ { id: 2, name: 'Slider' },
254
+ { id: 3, name: 'Video' },
255
+ { id: 4, name: 'Custom' },
256
+ ],
257
+ designs: [
258
+
259
+ {
260
+ 'thumbnail': 'preview/simple-01.png',
261
+ 'category': '1',
262
+ 'contentCss': 'type-poppins.css',
263
+ 'contentClass': 'type-poppins',
264
+ 'html': `
265
+ <div class="is-section is-box is-section-100 type-poppins">
266
+ ...
267
+ </div>`
268
+ },
269
+ // ...
270
+
271
+ ]
272
+ };
273
+
274
+ try {
275
+ template_list.push(data_templates);
276
+ } catch(e) {
277
+ //
278
+ }
279
+ ```
280
+
281
+ With the same format, you can create your own template set and load it in ContentBox.
282
+
283
+ In this JSON format, you can define the template set **name**, **categories**, and the template collection (**designs**).
284
+
285
+ Ini this set, we have 4 categories:
286
+ 1. Basic
287
+ 2. Slider
288
+ 3. Video
289
+ 4. Custom
290
+
291
+ For each section template, you need to specify:
292
+
293
+ - **thumbnail**
294
+ - **category**: see the **categories** definition **id**.
295
+ - **contentCss**: css file for typography (there are many css files you can choose from **assets/styles/** folder. Please choose the file with prefix **type-*****.
296
+ - **contentClass**: css class name (just use the css file name without extension)
297
+ - **html**: the HTML template.
298
+ Within the html, you can use **[%IMAGE_PATH%]** tag that will be replaced with the asset location/path. For example:
299
+ ```html
300
+ <img src="[%IMAGE_PATH%]images/photo.jpg">
301
+ ```
302
+ will become:
303
+ ```html
304
+ <img src="assets/simplestart/images/photo.jpg">
305
+ ```
306
+
307
+ Let's the other template file, the Quick Start template: **assets/quickstart/templates.js**.
308
+
309
+ ```javascript
310
+ var data_templates = {
311
+ name: 'Simple Start',
312
+ categories: [
313
+ { id: 1, name: 'Basic' },
314
+ { id: 2, name: 'Slider' },
315
+ { id: 3, name: 'Video' },
316
+ { id: 4, name: 'Custom' },
317
+ ],
318
+ designs: [
319
+
320
+ {
321
+ 'thumbnail': 'preview/simple-01.png',
322
+ 'category': '1',
323
+ 'contentCss': 'type-poppins.css',
324
+ 'contentClass': 'type-poppins',
325
+ 'html': `
326
+ <div class="is-section is-box is-section-100 type-poppins">
327
+ ...
328
+ </div>`
329
+ },
330
+ // ...
331
+
332
+ ]
333
+ };
334
+
335
+ try {
336
+ template_list.push(data_templates);
337
+ } catch(e) {
338
+ //
339
+ }
340
+ ```
341
+
342
+ Ini this set, we have 18 categories, from Header, Article, to Footer.
343
+
344
+ The two template files (**assets/simplestart/templates.js** and **assets/quickstart/templates.js**) are loaded by registering them in the **templates** parameter:
345
+
346
+
347
+ ```javascript
348
+ const builder = new ContentBox({
349
+ wrapper: '.is-wrapper',
350
+ templates: [
351
+ {
352
+ url: 'assets/simplestart/templates.js',
353
+ path: 'assets/simplestart/',
354
+ pathReplace: [ ]
355
+ },
356
+ {
357
+ url: 'assets/quickstart/templates.js',
358
+ path: 'assets/quickstart/',
359
+ pathReplace: [ ]
360
+ },
361
+ ],
362
+ });
363
+ ```
364
+
365
+ Template loading is asynchronous so it won’t block the initial page loading. In this configuration, we load the **simplestart/templates.js** set first and then the **quickstart/templates.js**.
366
+
367
+ #### Featuring Certain Categories
368
+
369
+ You can feature certain categories that will be displayed on the front using **featuredCategories** parameter:
370
+
371
+ ```javascript
372
+ const builder = new ContentBox({
373
+ // ...
374
+
375
+ featuredCategories: [
376
+ { id: 1, designId: 1, name: 'Basic' },
377
+ { id: 2, designId: 1, name: 'Slider' },
378
+ { id: 1, designId: 2, name: 'Header' },
379
+ { id: 2, designId: 2, name: 'Article' },
380
+ { id: 3, designId: 2, name: 'Photos' },
381
+ ],
382
+ });
383
+ ```
384
+
385
+ The **simplestart** set has designId=1 and the **quickstart** set has designId=2 (according to the load order).
386
+
387
+ The **id** refers to the category id.
388
+
389
+ Then choose which category to display on the first open:
390
+
391
+ ```javascript
392
+ const builder = new ContentBox({
393
+ // ...
394
+
395
+ defaultCategory: {
396
+ id: 1,
397
+ designId: 1
398
+ },
399
+ });
400
+ ```
401
+
402
+ Here we choose the **Basic** category (id: 1), from the **simplestart** set (designId: 1).
403
+
404
+ ![Featured Categories](docs/featured-categories.png)
405
+
406
+ #### Adjusting the thumbnail size
407
+
408
+ To adjust the template’s thumbnail size, use **templateThumbnailSize** parameter:
409
+
410
+ ```javascript
411
+ const builder = new ContentBox({
412
+ ...
413
+
414
+ templateThumbnailSize: 'small',
415
+ });
416
+ ```
417
+
418
+ The default is empty string (means dynamic or auto adjust based on the screen size).
419
+ For specific size, use: **small**, **medium**, or **large**.
420
+
421
+ ![Small](docs/template-small.png)
422
+
423
+ Small
424
+
425
+ ![Medium](docs/template-medium.png)
426
+
427
+ Medium
428
+
429
+ ![Large](docs/template-large.png)
430
+
431
+ Large
432
+
189
433
  ## Snippets
190
434
 
191
435
  Snippets are predesigned blocks that you can add or drag & drop into your content.
@@ -304,9 +548,9 @@ _txt['Italic'] = 'Italic';
304
548
 
305
549
  You can create your own language file by copying/modifying this file.
306
550
 
307
- ## Adding Custom Buttons to the Sidebar
551
+ ## Adding Custom Buttons on the Sidebar
308
552
 
309
- To add custom buttons to the sidebar, use the **addButton** method.
553
+ To add custom buttons on the sidebar, use the **addButton** method.
310
554
 
311
555
  Here is an example of adding the Undo & Redo button. For the undo and redo operation, we call the **undo()** and **redo()** methods.
312
556
 
@@ -568,7 +812,140 @@ const builder = new ContentBox({
568
812
  });
569
813
  ```
570
814
 
571
- More configuration options can be found in the ContentBuilder.js documentation: https://innovastudio.com/docs/contentbuilder.pdf
815
+ #### Preview
816
+
817
+ The editing toolbar from ContentBuilder.js has a **Preview** button to view the page result in a modal.
818
+ In ContentBox, you can define the preview URL using **previewURL** parameter. The default value is ‘preview.html’.
819
+
820
+ ```javascript
821
+ const builder = new ContentBox({
822
+ wrapper: '.is-wrapper',
823
+
824
+ previewURL: 'preview.html'
825
+ });
826
+ ```
827
+
828
+ ![Preview Button](docs/cb-preview.png)
829
+
830
+ The preview.html is used to view the edited page result (without the builder). The file is located in **public** folder.
831
+
832
+ More configuration options can be found in the ContentBuilder.js documentation:
833
+
834
+ https://innovastudio.com/docs/contentbuilder.pdf
835
+
836
+ ## Extending ContentBox with Custom Panel for Adding Custom Content
837
+
838
+ We will look on how to add a button on the sidebar that opens a custom panel. You can create your own custom panel by creating a simple html page. In this example, we will have a panel with multiple buttons that can add a custom content/section into your page. You can try the example in the package by opening: **public/example-custom.html**. (from localhost or from your server).
839
+
840
+ ![Extending ContentBox](docs/extending.png)
841
+
842
+ Click the buttons to try adding a new custom content/section into the page.
843
+
844
+ Let’s look at the code.
845
+
846
+ To add a button on the sidebar, use **addButton()** method (this method has been explained in the previous chapter: **Adding Custom Buttons on the Sidebar**):
847
+
848
+ ```javascript
849
+ builder.addButton({
850
+ 'pos': 0,
851
+ 'title': 'Products',
852
+ 'src': 'mypanel.html',
853
+ 'html': '<svg style="width:17px;height:17px;" viewBox="0 0 2048 2048" xmlns="http://www.w3.org/2000/svg">' +
854
+ '<g id="document" transform="matrix(1,0,0,1,1024.0,1024.0)"><path d="M178.271,508.452 L303.32,508.452 L303.32,-735.688 L178.271,-735.688 L178.271,508.452 Z " fill="#000000" fill-opacity="1.00" /><path d="M862.865,-51.0932 L862.865,-176.143 L-381.274,-176.143 L-381.274,-51.0933 L862.865,-51.0932 Z " fill="#000000" fill-opacity="1.00" /><path d="M-1020.43,275.099 L-1020.43,400.148 L-85.2735,400.148 L-85.2735,275.099 L-1020.43,275.099 Z " fill="#000000" fill-opacity="1.00" /><path d="M-1020.43,559.907 L-1020.43,684.956 L-85.2735,684.956 L-85.2735,559.907 L-1020.43,559.907 Z " fill="#000000" fill-opacity="1.00" /><path d="M-1024,844.714 L-1024,969.764 L-88.8389,969.764 L-88.8389,844.714 L-1024,844.714 Z " fill="#000000" fill-opacity="1.00" /></g>' +
855
+ '</svg>',
856
+ 'class': 'sidebar-sections'
857
+ });
858
+ ```
859
+
860
+ The **src** property is set with your custom html page, **mypanel.html**. This simple html page contains the buttons for adding content. Each button simply calls the **addSection()** method.
861
+
862
+
863
+ ```javascript
864
+ parent.contentbox.addSection(html, css)
865
+ ```
866
+
867
+ The **addSection()** method accepts two parameters:
868
+
869
+ - **html**: your content
870
+ - **css**: css file for typography that you can choose from the folder **assets/styles/**
871
+ (choose the file with prefix **type-**).
872
+
873
+ Example:
874
+
875
+ ```javascript
876
+ parent.contentbox.addSection(`
877
+ <div class="is-section is-box is-section-100 type-rufina-oxygen">
878
+ <div class="is-boxes">
879
+ <div class="is-box-centered">
880
+
881
+ <div class="is-container v2 is-content-960 leading-13 size-17">
882
+ <div class="row">
883
+ <div class="column full">
884
+ <h1 class="text-center leading-09 size-92">Product One</h1>
885
+ </div>
886
+ </div>
887
+ </div>
888
+
889
+ </div>
890
+ </div>
891
+ </div>
892
+ `, 'type-rufina-oxygen.css');
893
+ ```
894
+
895
+ Here we choose **type-rufina-oxygen.css** for the typography css. Then we added **type-rufina-oxygen** class in the **div.is-section** element. This will format the content with the Rufina & Oxygen fonts.
896
+
897
+ ```html
898
+ <div class="is-section is-box is-section-100 type-rufina-oxygen">
899
+ ...
900
+ </div>
901
+ ```
902
+
903
+ Use the same format as in the example if you want to create your own content. Please leave the other classes in the example as they are needed by ContentBox to format the content.
904
+
905
+ To make the content protected (non editable), please add **protected** class on the **div.is-section**. and do not use **is-container** class. The **is-container** class is used for text content inside the section and it is always editable.
906
+
907
+ ```html
908
+ <div class="is-section is-box is-section-100 type-rufina-oxygen protected">
909
+ ...
910
+ </div>
911
+ ```
912
+
913
+ If you need to add custom Javascript, please use the following format:
914
+
915
+ ```html
916
+ <div class="is-section is-box is-section-100 type-rufina-oxygen protected">
917
+ <div class="is-overlay">
918
+ <div class="is-overlay-content"
919
+ data-module="code"
920
+ data-module-desc="My Code"
921
+ data-html="[... encoded custom script here ...]">
922
+ </div>
923
+ </div>
924
+ </div>
925
+ ```
926
+
927
+ Here is an example:
928
+
929
+ ```javascript
930
+ parent.contentbox.addSection(`
931
+ <div class="is-section is-box is-section-100 is-light-text type-rufina-oxygen protected">
932
+ <div class="is-overlay">
933
+ <div class="is-overlay-content"
934
+ data-module="code"
935
+ data-module-desc="Custom HTML or Javascript "
936
+ data-html="${encodeURIComponent(`
937
+
938
+ <!-- custom script here -->
939
+
940
+ `)}">
941
+
942
+ </div>
943
+ </div>
944
+ </div>
945
+ `, 'type-rufina-oxygen.css');
946
+ ```
947
+
948
+ For the complete code, please open the **mypanel.html** with your code editor.
572
949
 
573
950
 
574
951
  ## Credits
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@innovastudio/contentbox",
3
3
  "type": "module",
4
- "version": "1.4.19",
4
+ "version": "1.4.21",
5
5
  "description": "",
6
6
  "main": "public/contentbox/contentbox.esm.js",
7
7
  "files": [
@@ -46,7 +46,7 @@
46
46
  "webpack-dev-server": "^4.0.0"
47
47
  },
48
48
  "dependencies": {
49
- "@innovastudio/contentbuilder": "^1.3.13",
49
+ "@innovastudio/contentbuilder": "^1.3.14",
50
50
  "js-beautify": "^1.14.0"
51
51
  }
52
52
  }
@@ -643,3 +643,7 @@
643
643
  .is-section.is-section-navbar .is-topbar {
644
644
  width: calc(100% - 60px);
645
645
  }
646
+
647
+ .is-section.protected .is-box-tool {
648
+ display: none !important;
649
+ }