@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 CHANGED
@@ -89,7 +89,7 @@ Powerful Page Builder for any growing merchants, brands, & agencies. Empower use
89
89
 
90
90
  ## Documentation
91
91
 
92
- ### Requirements
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
- ### Getting started & installation
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
- ### Quick Start
118
+ ## Quick Start
119
119
 
120
- Grammar: Should be "Get up and running quickly by initializing the builder in your Vue project. The following code example demonstrates the minimal setup required to start building pages.
120
+ ### Initializing the Page Builder
121
121
 
122
- - You must explicitly call initPageBuilder() once in your app entry (e.g. main.ts) before using any Page Builder features.
122
+ To get started with the Page Builder, follow these steps:
123
123
 
124
- - Then, use `getPageBuilder()` anywhere to access the shared builder instance.
125
-
126
- - Import the CSS file once, ideally in your `main.js`/`main.ts` or root component for proper styling and automatic icon loading.
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 builder instance
135
- // MUST be called once
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
- #### Accessing the Shared Page Builder Service
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
- Once you have initialized the Page Builder service in your application (by calling `initPageBuilder()` once in your app entry), you can access the shared instance anywhere by using the `getPageBuilder()` composable. This ensures you are always working with the same underlying builder service and state, keeping your application consistent and synchronized.
152
+ #### Why Use the Shared Instance?
145
153
 
146
- **Why Access the Shared Instance?**
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
- **There’s only one source of truth:**
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
- **How to Use the Shared Instance**
153
- Whenever you need to interact with the Page Builder service, import and call the `getPageBuilder()` function. This will return the existing instance you initialized earlier — no need to create a new one.
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
- ### Important: CSS Import Required
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
- **What does this mean for you?**
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
- - If you create your own custom components to use with the Page Builder (instead of the default ones), **remember that the builder will automatically add the `pbx-` prefix to every CSS class** in your component’s markup. This applies to both Tailwind utility classes and any custom classes you define.
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
- **Why is this important?**
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
- **When** you import the builder’s CSS file:
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
- **What does this mean for you?**
213
+ ## Rendering HTML Output in Other Frameworks (React, Nuxt, etc.)
232
214
 
233
- - **All Tailwind and custom CSS classes in this file prefixed with `pbx-` to prevent style conflicts.**.
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
- ### Rendering Only the HTML Output from the Page Builder in Other Frameworks (React, Nuxt, etc.)
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
- If you use the Page Builder to generate HTML pages and want to render them in another application (such as React, Nuxt, or any server-side app), simply install the Page Builder package in your target project and import its CSS file. This ensures that all prefix Tailwind and builder-specific styles are applied to the rendered HTML.
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 the necessary styles to any HTML output from the builder, even if you render it with `dangerouslySetInnerHTML`, `v-html`, or similar methods.
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:** You do not need to import any Vue components if you only want to render the HTML. Just import the CSS file.
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
- ### Provide Config to PageBuilder
251
+ The example below demonstrates the setup to start building pages, with additional options available for customization and branding.
271
252
 
272
- Get up and running quickly by importing the PageBuilder component, setting up your configuration, and initializing the builder in your Vue project. The following example demonstrates the minimal setup required to start building pages with your own config and logo.
253
+ Your `configPageBuilder` object can include:
273
254
 
274
- - Provide a `configPageBuilder` object to customize the builder, such as:
275
- - `formType` (required): Used to retrieve the correct content from local storage. Specify whether you are creating or updating a resource by setting this to `create` or `update` in the `updateOrCreate` config.
276
- - `formName` (required): Specify the resource type (e.g., `"article"`, `"jobPost"`, `"store"`, etc.) in the `updateOrCreate` config. This is especially useful if your platform supports multiple resource types. By providing a unique name, the Page Builder can correctly manage layouts and local storage for each resource type, allowing users to continue where they left off for different resources.
277
- - `resourceData` (optional): Prefill the builder with initial resource data (e.g., `"title"`, `"id"`).
278
- - `userForPageBuilder` (optional): Pass an object with user information (e.g., `name` and `image`) in your config to display the logged-in user's details within the builder interface.
279
- - `pageBuilderLogo` (optional): Display your company logo in the builder toolbar.
280
- - `userSettings` (optional): Set user preferences such as theme, language, or autoSave.
281
- - `brandColor` (optional): Set your brand’s primary color for key UI elements in the builder (inside the `settings` config).
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
- ### Local Storage & Auto-Save
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
- - **Auto-Save:** The builder periodically auto-saves your changes to local storage, so you don't have to worry about losing your work.
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
- #### Example: Retrieving the Most Up-to-Date HTML Content for Form Submission
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
- The Page Builder uses auto-save, so the data you retrieve from local storage always reflects the latest state of the builder—what the user currently sees in the editor. This means you are getting the most up-to-date content, saved live as the user edits.
317
+ ## Retrieving the Latest HTML Content for Form Submission
331
318
 
332
- To use the builder’s saved data in your form submission, you may want both the combined HTML content and the titles of each component. The `PageBuilderClass` provides a method to access the latest saved state from local storage. The example below demonstrates how to retrieve and parse this data, combining all component HTML into a single string and collecting all titles into an array. This is useful if you want to display or store both the rendered content and the structure or headings of your page.
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
- **Important:**
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 want to submit or save the builder’s output, for example, when the user clicks a “Save” or “Publish button. The code safely parses the local storage data, handles errors, and assigns the results to your form fields.
334
+ Call this logic when you need to submit or save the builder’s outputfor 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
- #### Resetting the Builder After Successful Resource Creation or Update
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.deleteAllComponents()
377
+ pageBuilderService.deleteAllComponentsFromDOM()
392
378
  // Clear Local Storage for the created or updated resource
393
- await pageBuilderService.removeItemComponentsLocalStorage()
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
- ### Loading Published Content from the Backend into the Page Builder
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
- You can easily load existing content—created with this Page Builder—from any backend source.
388
+ The `startBuilder` method accepts two arguments:
401
389
 
402
- - **Set `formType` (required):** This tells the builder to look for the correct content in local storage. Set `formType` to `update`.
403
- - **Set `formName` (required):** Specify the resource type (for example, `"article"`, `"jobPost"`, `"store"`, etc.) in the `updateOrCreate` config.
404
- - Even when loading an existing resource, these values are important if your platform supports multiple resource types. By providing a unique name, the Page Builder can properly manage layouts and local storage for the resource, allowing users to pick up right where they left off.
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 content from your backend or a JSON file into the Page Buildder
423
- await pageBuilderService.mountComponentsToDOM(JSON.stringify(html))
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
- Your `html.json` file should contain an array of component objects, each with a `html_code` and `title` (optional) property, as shown below:
433
-
434
- ```json
435
- {
436
- "components": [
437
- {
438
- "html_code": "<section><div class=\"relative py-4\"><div class=\"mx-auto max-w-7xl lg:px-4 px-2\"><div class=\"pbx-break-words pbx-text-5xl\"><h2><strong>Demo Content</strong></h2></div></div></div></section>",
439
- "title": "Header H2"
440
- },
441
- {
442
- "html_code": "<section>...</section>",
443
- "title": "Text"
444
- }
445
- // ...more components
446
- ]
447
- }
448
- ```
449
-
450
- This approach ensures your users can seamlessly load and edit previously published content, providing a smooth and reliable editing experience.
451
-
452
- ### Automatic Draft Recovery
453
-
454
- The Page Builder automatically checks for any unsaved drafts in local storage for the current resource.
455
- If a draft is found, users will be prompted to either continue where they left off or use the version currently loaded from your backend.
456
-
457
- - **`formType` (required):** Used to retrieve the correct content from local storage. Set this to either `create` or `update` in the `updateOrCreate` config, depending on your use case.
458
- - **`formName` (required):** Specify the resource type (e.g., `"article"`, `"jobPost"`, `"store"`, etc.) in the `updateOrCreate` config. This is especially useful if your platform supports multiple resource types. By providing a unique name, the Page Builder can correctly manage layouts and local storage for each resource type, allowing users to continue where they left off for different resources.
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
- // Retrieve Page Builder service instance
472
- const pageBuilderService = getPageBuilder()
473
- await pageBuilderService.startBuilder(configPageBuilder)
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>