@myissue/vue-website-page-builder 3.3.1 → 3.3.12
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 +134 -135
- package/dist/vue-website-page-builder.css +1 -1
- package/dist/vue-website-page-builder.js +4210 -4124
- package/dist/vue-website-page-builder.umd.cjs +37 -37
- package/package.json +1 -1
- package/src/Components/PageBuilder/EditorMenu/Editables/ComponentTopMenu.vue +4 -4
- package/src/Components/PageBuilder/EditorMenu/Editables/DeleteElement.vue +2 -2
- package/src/Components/PageBuilder/EditorMenu/Editables/ElementEditor.vue +2 -2
- package/src/Components/PageBuilder/EditorMenu/EditorAccordion.vue +1 -1
- package/src/Components/PageBuilder/ToolbarOption/ToolbarOption.vue +4 -4
- package/src/DemoComponents/HomeSection.vue +3 -2
- package/src/PageBuilder/PageBuilder.vue +3 -6
- package/src/composables/PageBuilderService.ts +333 -182
- package/src/helpers/isEmptyObject.ts +1 -1
- package/src/tailwind-safelist.html +1 -1
- package/src/types/index.ts +13 -1
package/README.md
CHANGED
|
@@ -89,7 +89,7 @@ Powerful Page Builder for any growing merchants, brands, & agencies. Empower use
|
|
|
89
89
|
|
|
90
90
|
## Documentation
|
|
91
91
|
|
|
92
|
-
|
|
92
|
+
## Requirements
|
|
93
93
|
|
|
94
94
|
Please note that these instructions assume you have Node.js installed.
|
|
95
95
|
|
|
@@ -97,7 +97,7 @@ Please note that these instructions assume you have Node.js installed.
|
|
|
97
97
|
- Vue.js ≥ 3.0.0
|
|
98
98
|
- Modern browser with ES6+ support
|
|
99
99
|
|
|
100
|
-
|
|
100
|
+
## Getting started & installation
|
|
101
101
|
|
|
102
102
|
Make sure to install the dependencies:
|
|
103
103
|
|
|
@@ -115,15 +115,15 @@ yarn install
|
|
|
115
115
|
bun install
|
|
116
116
|
```
|
|
117
117
|
|
|
118
|
-
|
|
118
|
+
## Quick Start
|
|
119
119
|
|
|
120
|
-
|
|
120
|
+
### Initializing the Page Builder
|
|
121
121
|
|
|
122
|
-
|
|
122
|
+
To get started with the Page Builder, follow these steps:
|
|
123
123
|
|
|
124
|
-
-
|
|
125
|
-
|
|
126
|
-
- Import the CSS file once
|
|
124
|
+
- **Call `initPageBuilder()` once** in your application entry point (e.g., `main.ts` or `main.js`). This sets up the shared builder instance for your entire app.
|
|
125
|
+
- **Access the shared builder instance** anywhere in your application using the `getPageBuilder()` composable.
|
|
126
|
+
- **Import the CSS file once** in your `main.js`, `main.ts`, or root component to ensure proper styling and automatic icon loading.
|
|
127
127
|
|
|
128
128
|
```typescript
|
|
129
129
|
import { createApp } from 'vue'
|
|
@@ -131,26 +131,37 @@ import App from './App.vue'
|
|
|
131
131
|
import { initPageBuilder } from '@myissue/vue-website-page-builder'
|
|
132
132
|
import '@myissue/vue-website-page-builder/style.css'
|
|
133
133
|
|
|
134
|
-
// Initialize shared
|
|
135
|
-
//
|
|
134
|
+
// Initialize the shared Page Builder instance
|
|
135
|
+
// This must be called once in your app entry point
|
|
136
136
|
initPageBuilder()
|
|
137
137
|
|
|
138
138
|
const app = createApp(App)
|
|
139
139
|
app.mount('#app')
|
|
140
140
|
```
|
|
141
141
|
|
|
142
|
-
|
|
142
|
+
> **Note:**
|
|
143
|
+
> You only need to import the CSS file once. If you have already imported it in your app entry, you do not need to import it again in individual components.
|
|
144
|
+
|
|
145
|
+
### Accessing the Shared Page Builder Service
|
|
146
|
+
|
|
147
|
+
After initializing the Page Builder service in your application (by calling `initPageBuilder()` once in your app entry point), you may access the shared instance from anywhere in your application using the `getPageBuilder()` composable.
|
|
148
|
+
|
|
149
|
+
> **Note**
|
|
150
|
+
> The Page Builder is implemented as a singleton service. This ensures that all page-building logic and state are managed by a single, shared instance throughout your application.
|
|
143
151
|
|
|
144
|
-
|
|
152
|
+
#### Why Use the Shared Instance?
|
|
145
153
|
|
|
146
|
-
|
|
147
|
-
The Page Builder is implemented as a singleton service. This means there is only one instance that manages all page-building logic and state across your app. Using this shared instance avoids creating multiple, isolated copies of the builder, which can lead to data inconsistencies, synchronization issues, and unpredictable behavior.
|
|
154
|
+
By always accessing the shared instance, you avoid creating multiple, isolated copies of the builder. This prevents data inconsistencies, synchronization issues, and unpredictable behavior. All components and modules interact with the same centralized service, ensuring that updates and state changes are reflected everywhere in your application.
|
|
148
155
|
|
|
149
|
-
|
|
150
|
-
By accessing the shared instance, your components and modules interact with the same centralized service, allowing smooth and reliable updates and coordination. This guarantees that all builder actions and state changes are reflected everywhere in your app.
|
|
156
|
+
#### Usage
|
|
151
157
|
|
|
152
|
-
|
|
153
|
-
|
|
158
|
+
Ensure the following configuration options are set:
|
|
159
|
+
|
|
160
|
+
- **`formType` (required):**
|
|
161
|
+
Indicates whether you are creating or updating a resource. This is used to retrieve the correct content from local storage.
|
|
162
|
+
|
|
163
|
+
- **`formName` (required):**
|
|
164
|
+
Specifies the resource type (for example, `article`, `jobPost`, `store`, etc.). This is essential for platforms supporting multiple resource types, as it enables the builder to manage layouts and local storage for each resource uniquely.
|
|
154
165
|
|
|
155
166
|
```vue
|
|
156
167
|
<script setup>
|
|
@@ -164,9 +175,10 @@ const configPageBuilder = {
|
|
|
164
175
|
},
|
|
165
176
|
}
|
|
166
177
|
|
|
167
|
-
// Retrieve Page Builder service instance
|
|
168
178
|
const pageBuilderService = getPageBuilder()
|
|
169
|
-
await pageBuilderService.startBuilder(configPageBuilder)
|
|
179
|
+
const result = await pageBuilderService.startBuilder(configPageBuilder)
|
|
180
|
+
|
|
181
|
+
console.log('You may inspect this result for message, status, or error:', result)
|
|
170
182
|
</script>
|
|
171
183
|
|
|
172
184
|
<template>
|
|
@@ -174,76 +186,42 @@ await pageBuilderService.startBuilder(configPageBuilder)
|
|
|
174
186
|
</template>
|
|
175
187
|
```
|
|
176
188
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
The Page Builder requires its CSS file to be imported for proper styling and automatic icon loading.
|
|
180
|
-
|
|
181
|
-
**You only need to import the CSS file once, ideally in your `main.js`/`main.ts` or root component.**
|
|
182
|
-
If you have already imported it in your app entry, you do not need to import it again in individual components.
|
|
183
|
-
|
|
184
|
-
```vue
|
|
185
|
-
<script setup>
|
|
186
|
-
import '@myissue/vue-website-page-builder/style.css'
|
|
187
|
-
</script>
|
|
188
|
-
```
|
|
189
|
-
|
|
190
|
-
This import automatically includes:
|
|
191
|
-
|
|
192
|
-
- ✅ Page Builder styles
|
|
193
|
-
- ✅ Responsive design utilities
|
|
194
|
-
|
|
195
|
-
### Important: CSS Prefix (`pbx-`) for All Builder Styles
|
|
196
|
-
|
|
197
|
-
The Page Builder automatically adds a `pbx-` prefix to **all CSS classes** it generates or processes, including Tailwind utility classes and any custom classes you add through the builder interface. This namespacing ensures that the builder’s styles will **not conflict** with your application's existing CSS or Tailwind classes.
|
|
189
|
+
## Important: CSS Prefixing (`pbx-`)
|
|
198
190
|
|
|
199
|
-
|
|
191
|
+
All CSS classes generated or processed by the Page Builder—including Tailwind utilities and your custom classes—are automatically prefixed with `pbx-`. This ensures the builder’s styles never conflict with your app’s existing CSS or Tailwind setup.
|
|
200
192
|
|
|
201
|
-
|
|
202
|
-
- For example, if you use a custom class called `myCustomCSSClass` in your component, it will be rendered as `pbx-myCustomCSSClass` in the final HTML output.
|
|
203
|
-
- All Tailwind classes are also prefixed, e.g. `bg-red-100` becomes `pbx-bg-red-100`, `md:grid-cols-2` becomes `md:pbx-grid-cols-2`, etc.
|
|
193
|
+
**How does this affect you?**
|
|
204
194
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
- The prefixing is done automatically by the builder to avoid style conflicts between the builder’s output and your own app’s CSS or Tailwind setup.
|
|
195
|
+
- Any class you use in builder components will be output as `pbx-ClassName`.
|
|
196
|
+
- Tailwind classes are also prefixed, e.g. `bg-red-100` becomes `pbx-bg-red-100`, `md:grid-cols-2` becomes `md:pbx-grid-cols-2`.
|
|
208
197
|
|
|
209
198
|
**Example:**
|
|
210
199
|
|
|
211
200
|
```html
|
|
212
|
-
<!-- Builder output -->
|
|
213
201
|
<div class="pbx-myCustomCSSClass pbx-bg-blue-100 md:pbx-grid-cols-2"></div>
|
|
214
202
|
```
|
|
215
203
|
|
|
216
204
|
```css
|
|
217
|
-
/* To style this element, use the pbx- prefix */
|
|
218
205
|
.pbx-myCustomCSSClass {
|
|
219
206
|
margin-bottom: 2rem;
|
|
220
207
|
}
|
|
221
208
|
```
|
|
222
209
|
|
|
223
|
-
**
|
|
224
|
-
|
|
225
|
-
```vue
|
|
226
|
-
<script setup>
|
|
227
|
-
import '@myissue/vue-website-page-builder/style.css'
|
|
228
|
-
</script>
|
|
229
|
-
```
|
|
210
|
+
> **Note:**
|
|
211
|
+
> Simply import the builder’s CSS file once in your project. All builder styles are namespaced, so there is no risk of style conflicts
|
|
230
212
|
|
|
231
|
-
|
|
213
|
+
## Rendering HTML Output in Other Frameworks (React, Nuxt, etc.)
|
|
232
214
|
|
|
233
|
-
|
|
234
|
-
- ✅ **There is no risk of style conflicts between the builder and your app, since all builder-related styles are namespaced.**.
|
|
215
|
+
You can use the Page Builder to generate HTML and render it in any frontend framework, such as React, Nuxt, or even server-side apps.
|
|
235
216
|
|
|
236
|
-
|
|
217
|
+
To ensure your content is styled correctly, simply install the Page Builder package in your target project and import its CSS file. All builder and Tailwind-prefixed styles will be applied automatically.
|
|
237
218
|
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
```vue
|
|
241
|
-
<script setup>
|
|
219
|
+
```js
|
|
220
|
+
// Import the builder's CSS file once in your project
|
|
242
221
|
import '@myissue/vue-website-page-builder/style.css'
|
|
243
|
-
</script>
|
|
244
222
|
```
|
|
245
223
|
|
|
246
|
-
This will apply all
|
|
224
|
+
This will apply all necessary styles to any HTML output from the builder, even if you render it with `dangerouslySetInnerHTML`, `v-html`, or similar methods.
|
|
247
225
|
|
|
248
226
|
**Example (React):**
|
|
249
227
|
|
|
@@ -265,20 +243,29 @@ import '@myissue/vue-website-page-builder/style.css'
|
|
|
265
243
|
|
|
266
244
|
Then use `v-html` to render the HTML.
|
|
267
245
|
|
|
268
|
-
> **Note:**
|
|
246
|
+
> **Note:**
|
|
247
|
+
> You do not need to import any Vue components if you only want to render the HTML. Just import the CSS file.
|
|
248
|
+
|
|
249
|
+
## Providing Configuration to the Page Builder
|
|
269
250
|
|
|
270
|
-
|
|
251
|
+
The example below demonstrates the setup to start building pages, with additional options available for customization and branding.
|
|
271
252
|
|
|
272
|
-
|
|
253
|
+
Your `configPageBuilder` object can include:
|
|
273
254
|
|
|
274
|
-
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
255
|
+
- **`formType` (required):**
|
|
256
|
+
Used to retrieve the correct content from local storage. Specify whether you are creating or updating a resource.
|
|
257
|
+
- **`formName` (required):**
|
|
258
|
+
The resource type (e.g., `article`, `jobPost`, `store`, etc.). This is especially useful for platforms supporting multiple resource types, allowing the builder to manage layouts and storage for each resource uniquely.
|
|
259
|
+
- **`resourceData` (optional):**
|
|
260
|
+
Prefill the builder with initial resource data (e.g., `title`, `id`).
|
|
261
|
+
- **`userForPageBuilder` (optional):**
|
|
262
|
+
Pass user information (such as `name` and `image`) to display the logged-in user’s details in the builder.
|
|
263
|
+
- **`pageBuilderLogo` (optional):**
|
|
264
|
+
Display your company logo in the builder toolbar.
|
|
265
|
+
- **`userSettings` (optional):**
|
|
266
|
+
Set user preferences such as theme, language, or auto-save.
|
|
267
|
+
- **`brandColor` (optional):**
|
|
268
|
+
Set your brand’s primary color for key UI elements (inside the `settings` config).
|
|
282
269
|
|
|
283
270
|
```vue
|
|
284
271
|
<script setup>
|
|
@@ -310,7 +297,9 @@ const configPageBuilder = {
|
|
|
310
297
|
|
|
311
298
|
// Retrieve Page Builder service instance
|
|
312
299
|
const pageBuilderService = getPageBuilder()
|
|
313
|
-
await pageBuilderService.startBuilder(configPageBuilder)
|
|
300
|
+
const result = await pageBuilderService.startBuilder(configPageBuilder)
|
|
301
|
+
|
|
302
|
+
console.log('You may inspect this result for message, status, or error:', result)
|
|
314
303
|
</script>
|
|
315
304
|
|
|
316
305
|
<template>
|
|
@@ -318,23 +307,20 @@ await pageBuilderService.startBuilder(configPageBuilder)
|
|
|
318
307
|
</template>
|
|
319
308
|
```
|
|
320
309
|
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
The Page Builder automatically manages all changes using the browser's local storage. Every change you make—such as adding, editing, or deleting components—is saved in local storage. This ensures your progress is not lost, even if you accidentally close the browser or navigate away.
|
|
310
|
+
## Local Storage & Auto-Save
|
|
324
311
|
|
|
325
|
-
|
|
326
|
-
- **Manual Save:** When the user clicks the Save button, the current state is also saved to local storage.
|
|
312
|
+
The Page Builder automatically saves all changes to the browser’s local storage. Every time you add, edit, or delete a component, your progress is preserved—even if you close the browser or navigate away.
|
|
327
313
|
|
|
328
|
-
|
|
314
|
+
- **Auto-Save:** Changes are periodically saved as you work.
|
|
315
|
+
- **Manual Save:** Clicking the Save button also stores the current state.
|
|
329
316
|
|
|
330
|
-
|
|
317
|
+
## Retrieving the Latest HTML Content for Form Submission
|
|
331
318
|
|
|
332
|
-
|
|
319
|
+
The builder’s auto-save ensures that the data in local storage always reflects the latest state of your page. You can retrieve this data at any time for form submission, publishing, or preview.
|
|
333
320
|
|
|
334
|
-
|
|
335
|
-
To retrieve the correct content from local storage, you must pass the same `resourceData` (such as `formType` and `formName`) to the Page Builder that was used when the content was originally saved. If the resource data does not match, the Page Builder will look for a different local storage key and may not find the expected content.
|
|
321
|
+
To get the most up-to-date content, use the same `resourceData` (such as `formType` and `formName`) that was used when saving. If these values do not match, the builder may not find the expected content.
|
|
336
322
|
|
|
337
|
-
Example
|
|
323
|
+
**Example:**
|
|
338
324
|
|
|
339
325
|
```js
|
|
340
326
|
const configPageBuilder = {
|
|
@@ -345,7 +331,7 @@ const configPageBuilder = {
|
|
|
345
331
|
}
|
|
346
332
|
```
|
|
347
333
|
|
|
348
|
-
Call this logic when you
|
|
334
|
+
Call this logic when you need to submit or save the builder’s output—for example, when the user clicks “Save” or “Publish.” The code below safely retrieves and parses the latest data from local storage, handling errors and assigning the results to your form fields.
|
|
349
335
|
|
|
350
336
|
```vue
|
|
351
337
|
<script setup>
|
|
@@ -380,7 +366,7 @@ try {
|
|
|
380
366
|
</script>
|
|
381
367
|
```
|
|
382
368
|
|
|
383
|
-
|
|
369
|
+
### Resetting the Builder After Successful Resource Creation or Update
|
|
384
370
|
|
|
385
371
|
After you have successfully created or updated a resource (such as a post, article, or listing) using the Page Builder, it is important to clear the builder’s draft state and remove the corresponding local storage entry. This ensures that old drafts do not appear the next time the builder is opened for a new or existing resource.
|
|
386
372
|
|
|
@@ -388,25 +374,29 @@ You can reset the builder state and clear the draft with:
|
|
|
388
374
|
|
|
389
375
|
```js
|
|
390
376
|
// Delete the HTML from the Live DOM
|
|
391
|
-
pageBuilderService.
|
|
377
|
+
pageBuilderService.deleteAllComponentsFromDOM()
|
|
392
378
|
// Clear Local Storage for the created or updated resource
|
|
393
|
-
await pageBuilderService.
|
|
379
|
+
await pageBuilderService.removeCurrentComponentsFromLocalStorage()
|
|
394
380
|
```
|
|
395
381
|
|
|
396
382
|
Always call these methods after a successful post or resource update to ensure users start with a fresh builder the next time they create or edit a resource.
|
|
397
383
|
|
|
398
|
-
|
|
384
|
+
## Loading existing Content or Components into the Page Builder
|
|
385
|
+
|
|
386
|
+
The Page Builder makes it simple to load previously published content from any backend source, such as your database or API.
|
|
399
387
|
|
|
400
|
-
|
|
388
|
+
The `startBuilder` method accepts two arguments:
|
|
401
389
|
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
390
|
+
1. **Configuration** (required):
|
|
391
|
+
The builder configuration object.
|
|
392
|
+
2. **Components Data** (optional):
|
|
393
|
+
An object containing existing components. This is especially useful when loading previously published or saved content into the builder.
|
|
394
|
+
|
|
395
|
+
If you provide the second argument, it must be an object with a `components` property, which is an array of objects. Each object must include a `html_code` string and may optionally include a `title` string.
|
|
405
396
|
|
|
406
397
|
```vue
|
|
407
398
|
<script setup>
|
|
408
399
|
import { getPageBuilder } from '@myissue/vue-website-page-builder'
|
|
409
|
-
import html from './html.json'
|
|
410
400
|
|
|
411
401
|
const configPageBuilder = {
|
|
412
402
|
updateOrCreate: {
|
|
@@ -415,12 +405,21 @@ const configPageBuilder = {
|
|
|
415
405
|
},
|
|
416
406
|
}
|
|
417
407
|
|
|
418
|
-
// Retrieve Page Builder service instance
|
|
408
|
+
// Retrieve the Page Builder service instance
|
|
419
409
|
const pageBuilderService = getPageBuilder()
|
|
420
|
-
await pageBuilderService.startBuilder(configPageBuilder)
|
|
421
410
|
|
|
422
|
-
// Load
|
|
423
|
-
|
|
411
|
+
// Load existing components into the builder (title is optional)
|
|
412
|
+
const myArticle = {
|
|
413
|
+
components: [
|
|
414
|
+
{ html_code: '<section>...</section>', title: 'Header H2' },
|
|
415
|
+
{ html_code: '<section>...</section>', title: 'Text' },
|
|
416
|
+
{ html_code: '<section>...</section>', title: 'Image' },
|
|
417
|
+
],
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
const result = await pageBuilderService.startBuilder(configPageBuilder, myArticle)
|
|
421
|
+
|
|
422
|
+
console.log('You may inspect this result for message, status, or error:', result)
|
|
424
423
|
</script>
|
|
425
424
|
|
|
426
425
|
<template>
|
|
@@ -428,34 +427,34 @@ await pageBuilderService.mountComponentsToDOM(JSON.stringify(html))
|
|
|
428
427
|
</template>
|
|
429
428
|
```
|
|
430
429
|
|
|
431
|
-
**Note:**
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
- **`
|
|
458
|
-
|
|
430
|
+
> **Note:**
|
|
431
|
+
> Each component’s `html_code` must be wrapped in a `<section>...</section>` tag.
|
|
432
|
+
> This is how the Page Builder defines and separates individual components.
|
|
433
|
+
>
|
|
434
|
+
> **Example:**
|
|
435
|
+
>
|
|
436
|
+
> ```json
|
|
437
|
+
> {
|
|
438
|
+
> "components": [
|
|
439
|
+
> {
|
|
440
|
+
> "html_code": "<section><div>My content</div></section>",
|
|
441
|
+
> "title": "Header"
|
|
442
|
+
> }
|
|
443
|
+
> ]
|
|
444
|
+
> }
|
|
445
|
+
> ```
|
|
446
|
+
|
|
447
|
+
This approach ensures your users can seamlessly load and edit previously published content, providing a smooth and reliable editing.
|
|
448
|
+
|
|
449
|
+
## Automatic Draft Recovery
|
|
450
|
+
|
|
451
|
+
The Page Builder automatically checks for unsaved drafts in local storage for the current resource.
|
|
452
|
+
If a draft is found, users are prompted to either continue where they left off or use the version loaded from your backend.
|
|
453
|
+
|
|
454
|
+
- **`formType` (required):**
|
|
455
|
+
Determines which draft to load from local storage. Set this to either `create` or `update` in the `updateOrCreate` config, depending on your use case.
|
|
456
|
+
- **`formName` (required):**
|
|
457
|
+
Specifies the resource type (e.g., `article`, `jobPost`, `store`, etc.) in the `updateOrCreate` config. This is especially important if your platform supports multiple resource types. By providing a unique name, the Page Builder can correctly manage layouts and drafts for each resource, allowing users to pick up where they left
|
|
459
458
|
|
|
460
459
|
```vue
|
|
461
460
|
<script setup>
|
|
@@ -468,9 +467,9 @@ const configPageBuilder = {
|
|
|
468
467
|
},
|
|
469
468
|
}
|
|
470
469
|
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
470
|
+
const result = await pageBuilderService.startBuilder(configPageBuilder)
|
|
471
|
+
|
|
472
|
+
console.log('You may inspect this result for message, status, or error:', result)
|
|
474
473
|
</script>
|
|
475
474
|
|
|
476
475
|
<template>
|