diff --git a/.editorconfig b/.editorconfig index 0f09989..c73c400 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,10 +1,10 @@ -# editorconfig.org -root = true - -[*] -indent_style = space -indent_size = 2 -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true +# editorconfig.org +root = true + +[*] +indent_style = space +indent_size = 2 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true diff --git a/.eslintrc b/.eslintrc index e70c7e0..e2eb10a 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,28 +1,28 @@ -{ - "root": true, - "parser": "@typescript-eslint/parser", - "plugins": ["@typescript-eslint", "eslint-comments"], - "ignorePatterns": ["node_modules", "dist", "dev", "tsup.config.ts"], - "parserOptions": { - "project": "./tsconfig.json", - "tsconfigRootDir": ".", - "sourceType": "module" - }, - "rules": { - "prefer-const": "warn", - "no-console": "warn", - "no-debugger": "warn", - "@typescript-eslint/no-unused-vars": [ - "warn", - { - "argsIgnorePattern": "^_", - "varsIgnorePattern": "^_", - "caughtErrorsIgnorePattern": "^_" - } - ], - "@typescript-eslint/no-unnecessary-type-assertion": "warn", - "@typescript-eslint/no-unnecessary-condition": "warn", - "@typescript-eslint/no-useless-empty-export": "warn", - "eslint-comments/no-unused-disable": "warn" - } -} +{ + "root": true, + "parser": "@typescript-eslint/parser", + "plugins": ["@typescript-eslint", "eslint-comments"], + "ignorePatterns": ["node_modules", "dist", "dev", "tsup.config.ts"], + "parserOptions": { + "project": "./tsconfig.json", + "tsconfigRootDir": ".", + "sourceType": "module" + }, + "rules": { + "prefer-const": "warn", + "no-console": "warn", + "no-debugger": "warn", + "@typescript-eslint/no-unused-vars": [ + "warn", + { + "argsIgnorePattern": "^_", + "varsIgnorePattern": "^_", + "caughtErrorsIgnorePattern": "^_" + } + ], + "@typescript-eslint/no-unnecessary-type-assertion": "warn", + "@typescript-eslint/no-unnecessary-condition": "warn", + "@typescript-eslint/no-useless-empty-export": "warn", + "eslint-comments/no-unused-disable": "warn" + } +} diff --git a/.github/ISSUE_TEMPLATE/bug-report.yml b/.github/ISSUE_TEMPLATE/bug-report.yml index 826905f..5bef31c 100644 --- a/.github/ISSUE_TEMPLATE/bug-report.yml +++ b/.github/ISSUE_TEMPLATE/bug-report.yml @@ -1,31 +1,31 @@ -name: "🐛 Bug report" -description: Create a report to help us improve -body: - - type: markdown - attributes: - value: | - Thank you for reporting an issue :pray:. - - The more information you fill in, the better the community can help you. - - type: textarea - id: description - attributes: - label: Describe the bug - description: Provide a clear and concise description of the challenge you are running into. - validations: - required: true - - type: input - id: link - attributes: - label: Minimal Reproduction Link - description: | - Please provide a link to a minimal reproduction of the bug you are running into. - It makes the process of verifying and fixing the bug much easier. - Note: - - Your bug will may get fixed much faster if we can run your code and it doesn't have dependencies other than the solid-js and solid-primitives. - - To create a shareable code example you can use [Stackblitz](https://stackblitz.com/) (https://solid.new). Please no localhost URLs. - - Please read these tips for providing a minimal example: https://stackoverflow.com/help/mcve. - placeholder: | - e.g. https://stackblitz.com/edit/...... OR Github Repo - validations: - required: true +name: "🐛 Bug report" +description: Create a report to help us improve +body: + - type: markdown + attributes: + value: | + Thank you for reporting an issue :pray:. + + The more information you fill in, the better the community can help you. + - type: textarea + id: description + attributes: + label: Describe the bug + description: Provide a clear and concise description of the challenge you are running into. + validations: + required: true + - type: input + id: link + attributes: + label: Minimal Reproduction Link + description: | + Please provide a link to a minimal reproduction of the bug you are running into. + It makes the process of verifying and fixing the bug much easier. + Note: + - Your bug will may get fixed much faster if we can run your code and it doesn't have dependencies other than the solid-js and solid-primitives. + - To create a shareable code example you can use [Stackblitz](https://stackblitz.com/) (https://solid.new). Please no localhost URLs. + - Please read these tips for providing a minimal example: https://stackoverflow.com/help/mcve. + placeholder: | + e.g. https://stackblitz.com/edit/...... OR Github Repo + validations: + required: true diff --git a/.github/ISSUE_TEMPLATE/feature-request.yml b/.github/ISSUE_TEMPLATE/feature-request.yml index e7c8598..29a6578 100644 --- a/.github/ISSUE_TEMPLATE/feature-request.yml +++ b/.github/ISSUE_TEMPLATE/feature-request.yml @@ -1,27 +1,27 @@ -name: "Feature Request" -description: For feature/enhancement requests. Please search for existing issues first. -body: - - type: markdown - attributes: - value: | - Thank you for bringing your ideas here :pray:. - - The more information you fill in, the better the community can understand your idea. - - type: textarea - id: problem - attributes: - label: Describe The Problem To Be Solved - description: Provide a clear and concise description of the challenge you are running into. - validations: - required: true - - type: textarea - id: solution - attributes: - label: Suggest A Solution - description: | - A concise description of your preferred solution. Things to address include: - - Details of the technical implementation - - Tradeoffs made in design decisions - - Caveats and considerations for the future - validations: - required: true +name: "Feature Request" +description: For feature/enhancement requests. Please search for existing issues first. +body: + - type: markdown + attributes: + value: | + Thank you for bringing your ideas here :pray:. + + The more information you fill in, the better the community can understand your idea. + - type: textarea + id: problem + attributes: + label: Describe The Problem To Be Solved + description: Provide a clear and concise description of the challenge you are running into. + validations: + required: true + - type: textarea + id: solution + attributes: + label: Suggest A Solution + description: | + A concise description of your preferred solution. Things to address include: + - Details of the technical implementation + - Tradeoffs made in design decisions + - Caveats and considerations for the future + validations: + required: true diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 3f37208..0f9d798 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -1,46 +1,46 @@ -name: "CodeQL" - -on: - push: - branches: [main] - pull_request: - branches: [main] - schedule: - - cron: "30 1 * * 0" - -jobs: - analyze: - name: Analyze - runs-on: ubuntu-latest - permissions: - security-events: write - - steps: - - name: Checkout repository - uses: actions/checkout@v3 - - - name: Initialize CodeQL - uses: github/codeql-action/init@v1 - with: - languages: javascript - - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v1 - with: - upload: false - output: sarif-results - - # Only include files that are public - - name: filter-sarif - uses: advanced-security/filter-sarif@main - with: - patterns: | - /src/**/*.* - -**/*.test.* - input: sarif-results/javascript.sarif - output: sarif-results/javascript.sarif - - - name: Upload SARIF - uses: github/codeql-action/upload-sarif@v1 - with: - sarif_file: sarif-results/javascript.sarif +name: "CodeQL" + +on: + push: + branches: [main] + pull_request: + branches: [main] + schedule: + - cron: "30 1 * * 0" + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-latest + permissions: + security-events: write + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Initialize CodeQL + uses: github/codeql-action/init@v1 + with: + languages: javascript + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v1 + with: + upload: false + output: sarif-results + + # Only include files that are public + - name: filter-sarif + uses: advanced-security/filter-sarif@main + with: + patterns: | + /src/**/*.* + -**/*.test.* + input: sarif-results/javascript.sarif + output: sarif-results/javascript.sarif + + - name: Upload SARIF + uses: github/codeql-action/upload-sarif@v1 + with: + sarif_file: sarif-results/javascript.sarif diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml index 4280668..89861dd 100644 --- a/.github/workflows/format.yml +++ b/.github/workflows/format.yml @@ -1,37 +1,37 @@ -name: Format - -on: - push: - branches: [main] - -jobs: - format: - runs-on: ubuntu-latest - - permissions: - # Give the default GITHUB_TOKEN write permission to commit and push the - # added or changed files to the repository. - contents: write - - steps: - - uses: actions/checkout@v3 - - uses: pnpm/action-setup@v2.2.4 - - - name: Setup Node.js environment - uses: actions/setup-node@v3 - with: - node-version: 18 - - # "git restore ." discards changes to package-lock.json - - name: Install dependencies - run: | - pnpm install --no-frozen-lockfile --ignore-scripts - git restore . - - - name: Format - run: pnpm run format - - - name: Add, Commit and Push - uses: stefanzweifel/git-auto-commit-action@v4 - with: - commit_message: 'Format' +name: Format + +on: + push: + branches: [main] + +jobs: + format: + runs-on: ubuntu-latest + + permissions: + # Give the default GITHUB_TOKEN write permission to commit and push the + # added or changed files to the repository. + contents: write + + steps: + - uses: actions/checkout@v3 + - uses: pnpm/action-setup@v2.2.4 + + - name: Setup Node.js environment + uses: actions/setup-node@v3 + with: + node-version: 18 + + # "git restore ." discards changes to package-lock.json + - name: Install dependencies + run: | + pnpm install --no-frozen-lockfile --ignore-scripts + git restore . + + - name: Format + run: pnpm run format + + - name: Add, Commit and Push + uses: stefanzweifel/git-auto-commit-action@v4 + with: + commit_message: 'Format' diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index f31b0a3..205023f 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -1,39 +1,39 @@ -name: Build and Test - -on: - push: - branches: [main] - pull_request: - branches: [main] - -jobs: - build: - runs-on: ubuntu-latest - - steps: - - name: Checkout repo - uses: actions/checkout@v3 - with: - fetch-depth: 2 - - - uses: pnpm/action-setup@v2.2.4 - - - name: Setup Node.js environment - uses: actions/setup-node@v3 - with: - node-version: 18 - cache: pnpm - - - name: Install dependencies - run: pnpm install - - - name: Build - run: pnpm run build - - - name: Test - run: pnpm run test - env: - CI: true - - - name: Lint - run: pnpm run lint +name: Build and Test + +on: + push: + branches: [main] + pull_request: + branches: [main] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout repo + uses: actions/checkout@v3 + with: + fetch-depth: 2 + + - uses: pnpm/action-setup@v2.2.4 + + - name: Setup Node.js environment + uses: actions/setup-node@v3 + with: + node-version: 18 + cache: pnpm + + - name: Install dependencies + run: pnpm install + + - name: Build + run: pnpm run build + + - name: Test + run: pnpm run test + env: + CI: true + + - name: Lint + run: pnpm run lint diff --git a/.gitignore b/.gitignore index ef9299e..6af5a88 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ -node_modules -dist -gitignore - -# tsup -tsup.config.bundled_*.{m,c,}s +node_modules +dist +gitignore + +# tsup +tsup.config.bundled_*.{m,c,}s diff --git a/.prettierrc b/.prettierrc index 5012e01..bf354e9 100644 --- a/.prettierrc +++ b/.prettierrc @@ -1,10 +1,10 @@ -{ - "trailingComma": "all", - "tabWidth": 2, - "printWidth": 100, - "semi": false, - "singleQuote": true, - "useTabs": false, - "arrowParens": "avoid", - "bracketSpacing": true -} +{ + "trailingComma": "all", + "tabWidth": 2, + "printWidth": 100, + "semi": false, + "singleQuote": true, + "useTabs": false, + "arrowParens": "avoid", + "bracketSpacing": true +} diff --git a/.vscode/extensions.json b/.vscode/extensions.json index d7df89c..7f7c01e 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -1,3 +1,3 @@ -{ - "recommendations": ["esbenp.prettier-vscode", "dbaeumer.vscode-eslint"] -} +{ + "recommendations": ["esbenp.prettier-vscode", "dbaeumer.vscode-eslint"] +} diff --git a/LICENSE b/LICENSE index 2ba7ae7..1f12ab9 100644 --- a/LICENSE +++ b/LICENSE @@ -1,201 +1,201 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright 2024 insertish - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright 2024 insertish + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/PORTING.md b/PORTING.md new file mode 100644 index 0000000..1ad7473 --- /dev/null +++ b/PORTING.md @@ -0,0 +1,246 @@ +# PORTING.md — Porting @livekit/components-react to Solid.js + +This document records the systematic translation patterns used when porting +hooks and components from `@livekit/components-react` to this Solid.js library. +Read this before porting any new file. It will save you from repeating bugs +already found and fixed. + +--- + +## The three-layer architecture + +The upstream LiveKit components stack has three layers: + +``` +livekit-client raw Room/Participant/Track SDK, framework-agnostic +@livekit/components-core RxJS observables wrapping SDK events, framework-agnostic +@livekit/components-react React hooks consuming core observables +solid-livekit-components THIS LIBRARY: Solid signals consuming core observables +``` + +Key point: we share `@livekit/components-core` with the React library. Do not +reimplement what core already provides. Use `connectionStateObserver`, +`mutedObserver`, `participantObserver` etc. from core rather than subscribing to +raw `livekit-client` Room events directly. + +--- + +## Source version annotation + +Every ported file carries a version comment at the top: + +```typescript +// @livekit/components-react@2.0.4 +// Apache-2.0 +``` + +When the upstream React library releases a new version, check the changelog and +update ported files that have changed. The version comment is your diff anchor. + +--- + +## Translation patterns + +### 1. useState + useEffect becomes createSignal + useObservableState + +The most common pattern in the React library is: + +```typescript +// React +const [state, setState] = React.useState(initialValue) +React.useEffect(() => { + const sub = someObservable.subscribe(setState) + return () => sub.unsubscribe() +}, [someObservable]) +return state +``` + +In Solid, use `useObservableState` from `./internal/useObservableState`: + +```typescript +// Solid +const observable = createMemo(() => someObservable) +return useObservableState(observable(), initialValue) +``` + +`useObservableState` handles the subscription and cleanup internally. Use it +for every observable-to-signal conversion. + +### 2. NEVER pass a dependency array to createEffect + +This is the most critical bug to avoid. React's `useEffect` accepts a +dependency array as its second argument. Solid's `createEffect` does NOT. +Solid tracks reactive dependencies automatically by reading signals inside the +effect body. + +```typescript +// WRONG — Solid silently ignores the second argument. +// The effect runs once and never re-runs when dep changes. +createEffect(() => { + doSomethingWith(dep) +}, [dep]) + +// CORRECT — Solid tracks dep automatically because it is read inside the effect. +createEffect(() => { + doSomethingWith(dep()) +}) +``` + +If you need an effect to re-run when a derived value changes, wrap it in +`createMemo` first and read the memo inside the effect: + +```typescript +const observable = createMemo(() => mutedObserver(trackRef)) +createEffect(() => { + const sub = observable().subscribe(handler) + onCleanup(() => sub.unsubscribe()) +}) +``` + +### 3. RoomContext holds Accessor, not Room + +In this library, `RoomContext` is typed as `createContext>`. +This means the context value is a signal getter function, not the Room directly. + +```typescript +// Accessing the room from context — note the double call ()() +const roomAccessor = useRoomContext() // returns Accessor +const room = roomAccessor() // call it to get the Room value + +// useEnsureRoom wraps this pattern and throws if no room is available +const r = useEnsureRoom() // returns () => Room (throws if undefined) +const room = r() // call to get the Room +``` + +When you port a React hook that calls `useRoomContext()` and uses the result +directly, wrap the usage in a `createMemo` or read it inside a reactive context: + +```typescript +// React +const room = useRoomContext() +const observable = connectionStateObserver(room) + +// Solid +const r = useEnsureRoom() +const observable = createMemo(() => connectionStateObserver(r())) +return useObservableState(observable(), r().state) +``` + +### 4. useRef becomes a plain variable + +React requires `useRef` because component functions re-run on every render. +Solid component functions run once. DOM refs are just variables: + +```typescript +// React +const mediaEl = React.useRef(null) +return