{"id":26666452,"url":"https://github.com/allnulled/lsw-dialogs","last_synced_at":"2025-03-25T18:35:11.888Z","repository":{"id":275949978,"uuid":"927077262","full_name":"allnulled/lsw-dialogs","owner":"allnulled","description":"Dialogs manager tool for LSW","archived":false,"fork":false,"pushed_at":"2025-03-24T17:50:26.000Z","size":22,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-24T18:46:14.626Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/allnulled.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-02-04T11:14:59.000Z","updated_at":"2025-03-24T17:50:28.000Z","dependencies_parsed_at":null,"dependency_job_id":"b6bb80fb-6ef4-45ae-912d-ceb037e025e9","html_url":"https://github.com/allnulled/lsw-dialogs","commit_stats":null,"previous_names":["allnulled/lsw-dialogs"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/allnulled%2Flsw-dialogs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/allnulled%2Flsw-dialogs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/allnulled%2Flsw-dialogs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/allnulled%2Flsw-dialogs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/allnulled","download_url":"https://codeload.github.com/allnulled/lsw-dialogs/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245521267,"owners_count":20629050,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-03-25T18:35:11.421Z","updated_at":"2025-03-25T18:35:11.879Z","avatar_url":"https://github.com/allnulled.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# lsw-dialogs\n\nDialogs manager tool for LSW.\n\nBased on [vue@2](#).\n\n## Installation\n\n```sh\nnpm i -s @allnulled/lsw-dialogs\n```\n\n## Importation\n\n```html\n\u003cscript src=\"node_modules/@allnulled/lsw-dialogs/lsw-dialogs.compiled.js\"\u003e\u003c/script\u003e\n\u003clink rel=\"stylesheet\" type=\"text/css\" href=\"node_modules/@allnulled/lsw-dialogs/lsw-dialogs.css\" /\u003e\n```\n\nThe *compiled version* is because the template is injected to the JavaScript via a simple replace (but it is still needed).\n\nThen you have to include it on you `vue@2` markup, somewhere:\n\n```html\n\u003clsw-dialogs /\u003e\n```\n\nThen magic can work.\n\n## Usage\n\nThis example only misses the `parentId`, which can be extracted from `LswDialogs.opened[$id]` and references to a parent process in the processes tree.\n\n```js\nconst userData = await LswDialogs.open({\n  // defaults to \"default\", used to identify the dialog on LswDialogs.opened[?]\n  id: \"collecting-user-data-dialog\",\n  // defaults to undefined, used to close children processes when a parent process is closed\n  parentId: undefined,\n  // defaults to 500, used to organize the z-index css property in live\n  priority: 500,\n  // defaults to \"\", used to identify the window by the header on the UI\n  title: \"Collecting user data\",\n  // template is not optional, used as template for the vue@2 component\n  template: `\n    \u003cdiv\u003e\n      \u003cinput type=\"text\" v-model=\"value.name\" style=\"width:100%;\" placeholder=\"Nombre\" /\u003e\n      \u003cinput type=\"number\" v-model=\"value.age\" style=\"width:100%;\" placeholder=\"Edad\" /\u003e\n      \u003cinput type=\"text\" v-model=\"value.city\" style=\"width:100%;\" placeholder=\"Ciudad\" /\u003e\n      \u003cbutton v-on:click=\"accept\"\u003eAceptar\u003c/button\u003e\n    \u003c/div\u003e\n  `,\n  // factory can be a function that returns an object too, used as definition of the vue@2 component\n  factory: {\n    // data can be a function that returns an object too, used as part of the vue@2 component definition\n    data: {\n      // data.value is what is returned by default on 'accept' injected method\n      value: {\n        name: \"Guybrush Threwpood\",\n        age: 35,\n        city: \"Inda Siri\"\n      }\n    }\n  }\n});\nconsole.log(userData);\n```\n\nThe parameters `factory` and `data` can be functions too. Like `vue@2`.\n\n## API\n\nThe API is composed mainly by 2 kinds of artifacts: the manager, and the dialogs.\n\nThe manager corresponds directly to the vue@2 component that manages the dialogs stuff, `LswDialogs`.\n\nThe dialogs are abstractions that the manager knows how to render, and tracks their *opens*, *resolve/reject*, *closes* properly. Basically.\n\n### 1. Dialogs manager\n\nThe dialogs are handled by `LswDialogs.opened` map. Its keys are the `id` of the dialog.\n\nUsing `await LswDialogs.open({ ... })` you can invoke a dialog and extract the form data.\n\nUsing `await LswDialogs.close(id)` you can close a dialog and its children.\n\nUsing `LswDialogs.opened` you can access the currently active dialogs.\n\nThen, on `LswDialogs.open({...})`, you have to provide a dialog signature, as shown on the example. Below, it is further explained.\n\n### 2. Dialogs signature\n\nThis is the signature that a dialog must provide:\n\n```js\nclass Dialog {\n    static fromIdToComponentName(id) {\n      return \"lsw-dialog-\" + id;\n    }\n    constructor(info = {}) {\n      Object.assign(this, info);\n      Validations: {\n        if (typeof this.id !== \"string\") {\n          throw new Error(`Required parameter «dialog.id» to be a string on «Dialog.constructor»`);\n        }\n        if (typeof this.name !== \"string\") {\n          throw new Error(`Required parameter «dialog.name» to be a string on «Dialog.constructor»`);\n        }\n        if (typeof this.priority !== \"number\") {\n          throw new Error(`Required parameter «dialog.priority» to be a number on «Dialog.constructor»`);\n        }\n        if (typeof this.component !== \"object\") {\n          throw new Error(`Required parameter «dialog.component» to be an object on «Dialog.constructor»`);\n        }\n        if (typeof this.promiser !== \"object\") {\n          throw new Error(`Required parameter «dialog.promiser» to be an object on «Dialog.constructor»`);\n        }\n        if (!(this.promiser.promise instanceof Promise)) {\n          throw new Error(`Required parameter «dialog.promiser.promise» to be an instance of Promise on «Dialog.constructor»`);\n        }\n        if (typeof this.promiser.resolve !== \"function\") {\n          throw new Error(`Required parameter «dialog.promiser.resolve» to be an function on «Dialog.constructor»`);\n        }\n        if (typeof this.promiser.reject !== \"function\") {\n          throw new Error(`Required parameter «dialog.promiser.reject» to be an function on «Dialog.constructor»`);\n        }\n      }\n    }\n  }\n```\n\nYou do not have to provide all of these properties. From you, what is expected, is specified here:\n\n```js\nconst {\n  template,\n  title = \"\",\n  id = \"default\",\n  priority = 0,\n  factory = defaultDialogFactory,\n  parentId = undefined,\n} = parametricObject;\n```\n\nSo, as you can see, only `template` is required.\n\nFurther from this, is all about how the API works, and it only takes around 300 lines to understand deeper what it does.\n\nSo, if you want to use it, I think this is enough to start. And if you want to fork/customize/intensively explote, you can explore the sources.\n\n## Extras de LSW\n\nPara ponerle los botones de aceptar o cancelar, puedes usar los parámetros:\n\n```js\nawait Vue.prototype.$dialogs.open({\n  title: \"Example of bottom buttons customization\",\n  template: `\n    \u003cdiv\u003e\n      \u003cp\u003eOK, there we go!\u003c/p\u003e\n    \u003c/div\u003e\n  `,\n  factory: {\n    data: {\n      acceptButton: {\n        text: \"OK\",\n        callback: function() {}\n      },\n      cancelButton: {\n        text: \"Nope, no way!\",\n        callback: function() {}\n      }\n    }\n  }\n});\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fallnulled%2Flsw-dialogs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fallnulled%2Flsw-dialogs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fallnulled%2Flsw-dialogs/lists"}