├── lib ├── swish.ex └── swish │ ├── dialog │ └── transitions.ex │ ├── el.ex │ ├── js.ex │ ├── tag.ex │ ├── form.ex │ └── dialog.ex ├── test ├── test_helper.exs └── swish_test.exs ├── assets ├── index.js ├── hooks │ ├── index.js │ └── portal.js └── utils │ └── attribute.js ├── .formatter.exs ├── package.json ├── .gitignore ├── config └── config.exs ├── priv └── static │ ├── swish.min.js │ ├── swish.esm.js │ ├── swish.cjs.js │ ├── swish.js │ ├── swish.esm.js.map │ └── swish.cjs.js.map ├── mix.exs ├── README.md ├── mix.lock └── LICENSE /lib/swish.ex: -------------------------------------------------------------------------------- 1 | defmodule Swish do 2 | end 3 | -------------------------------------------------------------------------------- /test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /assets/index.js: -------------------------------------------------------------------------------- 1 | import Hooks from "./hooks"; 2 | 3 | export default { 4 | Hooks 5 | } 6 | -------------------------------------------------------------------------------- /assets/hooks/index.js: -------------------------------------------------------------------------------- 1 | import Portal from "./portal"; 2 | 3 | export default { 4 | "Swish.Portal": Portal 5 | } 6 | -------------------------------------------------------------------------------- /test/swish_test.exs: -------------------------------------------------------------------------------- 1 | defmodule SwishTest do 2 | use ExUnit.Case 3 | 4 | import Phoenix.Component 5 | import Phoenix.LiveViewTest 6 | end 7 | -------------------------------------------------------------------------------- /.formatter.exs: -------------------------------------------------------------------------------- 1 | # Used by "mix format" 2 | [ 3 | plugins: [Phoenix.LiveView.HTMLFormatter], 4 | inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"] 5 | ] 6 | -------------------------------------------------------------------------------- /lib/swish/dialog/transitions.ex: -------------------------------------------------------------------------------- 1 | defmodule Swish.Dialog.Transitions do 2 | @moduledoc """ 3 | Describes the available transitions for a dialog. 4 | """ 5 | 6 | defstruct [:show_content, :hide_content, :show_backdrop, :hide_backdrop] 7 | end 8 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "swish", 3 | "version": "0.0.0", 4 | "description": "Swish", 5 | "license": "MIT", 6 | "module": "./priv/static/swish.esm.js", 7 | "main": "./priv/static/swish.cjs.js", 8 | "unpkg": "./priv/static/swish.min.js", 9 | "jsdelivr": "./priv/static/swish.min.js", 10 | "exports": { 11 | "import": "./priv/static/swish.esm.js", 12 | "require": "./priv/static/swish.cjs.js" 13 | }, 14 | "files": [ 15 | "README.md", 16 | "LICENSE.md", 17 | "package.json", 18 | "assets/*" 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /lib/swish/el.ex: -------------------------------------------------------------------------------- 1 | defmodule Swish.EL do 2 | @moduledoc false 3 | 4 | def new_id(prefix, escaped \\ false) 5 | def new_id(prefix, true), do: "##{prefix}-#{System.unique_integer([:positive])}" 6 | def new_id(prefix, false), do: "#{prefix}-#{System.unique_integer([:positive])}" 7 | 8 | def get_id(el, escaped \\ false) 9 | def get_id(%{id: id}, true), do: "##{id}" 10 | def get_id(%{id: id}, false), do: "#{id}" 11 | 12 | def suffix_id(el, suffix, escaped \\ false) 13 | def suffix_id(%{id: id}, suffix, true), do: "##{id}-#{suffix}" 14 | def suffix_id(%{id: id}, suffix, false), do: "#{id}-#{suffix}" 15 | 16 | def event(name), do: "swish:#{name}" 17 | end 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build/ 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover/ 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps/ 9 | 10 | # Where third-party dependencies like ExDoc output generated docs. 11 | /doc/ 12 | 13 | # Ignore .fetch files in case you like to edit your project deps locally. 14 | /.fetch 15 | 16 | # If the VM crashes, it generates a dump, let's ignore it too. 17 | erl_crash.dump 18 | 19 | # Also ignore archive artifacts (built via "mix archive.build"). 20 | *.ez 21 | 22 | # Ignore package tarball (built via "mix hex.build"). 23 | swish-*.tar 24 | 25 | # Temporary files, for example, from tests. 26 | /tmp/ 27 | -------------------------------------------------------------------------------- /config/config.exs: -------------------------------------------------------------------------------- 1 | import Config 2 | 3 | if Mix.env() == :dev do 4 | esbuild = fn args -> 5 | [ 6 | args: ~w(./index.js --bundle) ++ args, 7 | cd: Path.expand("../assets", __DIR__), 8 | env: %{"NODE_PATH" => Path.expand("../deps", __DIR__)} 9 | ] 10 | end 11 | 12 | config :esbuild, 13 | version: "0.12.15", 14 | module: esbuild.(~w(--format=esm --sourcemap --outfile=../priv/static/swish.esm.js)), 15 | main: esbuild.(~w(--format=cjs --sourcemap --outfile=../priv/static/swish.cjs.js)), 16 | cdn: esbuild.(~w(--format=iife --target=es2016 --global-name=LiveView --outfile=../priv/static/swish.js)), 17 | cdn_min: esbuild.(~w(--format=iife --target=es2016 --global-name=LiveView --minify --outfile=../priv/static/swish.min.js)) 18 | end 19 | 20 | -------------------------------------------------------------------------------- /assets/utils/attribute.js: -------------------------------------------------------------------------------- 1 | export function getAttributeOrThrow(element, attr, transform = null) { 2 | if (!element.hasAttribute(attr)) { 3 | throw new Error( 4 | `Missing attribute '${attr}' on element <${element.tagName}:${element.id}>` 5 | ); 6 | } 7 | 8 | const value = element.getAttribute(attr); 9 | 10 | return transform ? transform(value) : value; 11 | } 12 | 13 | export function getAttributeOrDefault( 14 | element, 15 | attr, 16 | defaultValue, 17 | transform = null 18 | ) { 19 | if (element.hasAttribute(attr)) { 20 | const value = element.getAttribute(attr); 21 | return transform ? transform(value) : value; 22 | } else { 23 | return defaultValue; 24 | } 25 | } 26 | 27 | export function getElementAttributeOrThrow(element, type, attr) { 28 | if (!(element instanceof type)) throw new Error(`Element is not of type '${type}'`); 29 | return getAttributeOrThrow(element, attr); 30 | } 31 | 32 | export function parseBoolean(value) { 33 | if (value === "true") { 34 | return true; 35 | } 36 | 37 | if (value === "false") { 38 | return false; 39 | } 40 | 41 | throw new Error( 42 | `Invalid boolean attribute ${value}, should be either "true" or "false"` 43 | ); 44 | } 45 | 46 | export function parseInteger(value) { 47 | const number = parseInt(value, 10); 48 | 49 | if (Number.isNaN(number)) { 50 | throw new Error(`Invalid integer value ${value}`); 51 | } 52 | 53 | return number; 54 | } -------------------------------------------------------------------------------- /priv/static/swish.min.js: -------------------------------------------------------------------------------- 1 | var LiveView=(()=>{var i=Object.defineProperty;var u=t=>i(t,"__esModule",{value:!0});var h=(t,e)=>{u(t);for(var o in e)i(t,o,{get:e[o],enumerable:!0})};var b={};h(b,{default:()=>f});function n(t,e,o=null){if(!t.hasAttribute(e))throw new Error(`Missing attribute '${e}' on element <${t.tagName}:${t.id}>`);let r=t.getAttribute(e);return o?o(r):r}function s(t){let e=parseInt(t,10);if(Number.isNaN(e))throw new Error(`Invalid integer value ${t}`);return e}var d=Object.keys(window).filter(t=>/\bon/.test(t));function c(t,e){for(let o of d)e.addEventListener(o,r=>{r.stopPropagation(),t.dispatchEvent(new r.constructor(r.type,r))})}var p={prepend:(t,e)=>{t.parentNode.insertBefore(e,t)},append:(t,e)=>{t.parentNode.insertBefore(e,t.nextSibling)},origin:(t,e)=>{t.appendChild(e)}},l={clone:null,target:null,update:null,closeDelay:null,closeTimeout:null,mounted(){let t=n(this.el,"data-target");this.target=document.querySelector(t),this.update=n(this.el,"data-update"),this.closeDelay=n(this.el,"data-close-delay",s),this.el.addEventListener("portal:open",this.handleOpen.bind(this)),this.el.addEventListener("portal:close",this.handleClose.bind(this))},destroyed(){this.clone.remove(),clearTimeout(this.closeTimeout)},handleOpen(){this.clone=this.el.content.cloneNode(!0).firstElementChild,p[this.update](this.target,this.clone),c(this.el,this.clone)},handleClose(){let t=this.clone;this.closeTimeout=setTimeout(()=>t.remove(),this.closeDelay)}};var a={"Swish.Portal":l};var f={Hooks:a};return b;})(); 2 | -------------------------------------------------------------------------------- /mix.exs: -------------------------------------------------------------------------------- 1 | defmodule Swish.MixProject do 2 | use Mix.Project 3 | 4 | @version "0.0.0" 5 | @url "https://github.com/thiagomajesk/swish" 6 | 7 | def project do 8 | [ 9 | app: :swish, 10 | version: @version, 11 | elixir: "~> 1.14", 12 | start_permanent: Mix.env() == :prod, 13 | aliases: aliases(), 14 | description: description(), 15 | package: package(), 16 | docs: docs(), 17 | deps: deps() 18 | ] 19 | end 20 | 21 | defp description() do 22 | """ 23 | Swish is a UI toolkit for busy developers and a "no frills" replacement for the standard Phoenix 1.7 core components. 24 | This project aims to provide unstyled component primitives that you can use directly to speed up your development workflow. 25 | """ 26 | end 27 | 28 | defp package do 29 | [ 30 | maintainers: ["Thiago Majesk Goulart"], 31 | licenses: ["AGPL-3.0-only"], 32 | links: %{"GitHub" => @url}, 33 | files: ~w(lib mix.exs README.md LICENSE assets package.json) 34 | ] 35 | end 36 | 37 | defp docs() do 38 | [ 39 | source_ref: "v#{@version}", 40 | main: "README", 41 | canonical: "http://hexdocs.pm/swish", 42 | source_url: @url, 43 | extras: [ 44 | "README.md": [filename: "README"] 45 | ] 46 | ] 47 | end 48 | 49 | # Run "mix help compile.app" to learn about applications. 50 | def application do 51 | [ 52 | extra_applications: [:logger] 53 | ] 54 | end 55 | 56 | # Run "mix help deps" to learn about dependencies. 57 | defp deps do 58 | [ 59 | {:phoenix_live_view, "~> 0.18.18"}, 60 | {:phoenix_html, "~> 3.3.1"}, 61 | {:gettext, "~> 0.20"}, 62 | {:ex_doc, "~> 0.29", only: :dev, runtime: false}, 63 | {:esbuild, "~> 0.2", only: :dev, runtime: false} 64 | ] 65 | end 66 | 67 | defp aliases do 68 | [ 69 | "assets.build": ["esbuild module", "esbuild cdn", "esbuild cdn_min", "esbuild main"], 70 | "assets.watch": ["esbuild module --watch"] 71 | ] 72 | end 73 | end 74 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Swish 2 | 3 | Swish is a UI toolkit for busy developers that provides a set unstyled component primitives, also know as "headless components", that you can to speed up your development workflow. 4 | 5 | # The project 6 | 7 | Phoenix 1.7 introduces a set of pre-generated core components which brings some flexibility. However, we've found that the work necessary to maintain those components in each project your work on is a little taxing for most developers. 8 | 9 | This library aims to reduce the amount of work necessary to maintain and reuse components by providing the expected behaviors through a terse API that you can use to build, customize and style your own components. 10 | 11 | 12 | ### Goals 13 | 14 | - ✅ Provide a API somewhat compatible with the existing Phoenix.HTML helpers 15 | - ✅ Provide set of components with built-in behaviors that you can style to create complete UIs on your own 16 | - ✅ Provide a bare minimum degree of accessibility that you are most likely not going to implement by yourself 17 | - ✅ Allow the customization of component behaviors through a easy-to-use and well documented API 18 | 19 | Before using this library, it's important to understand that there are many different chalenges regarding UI design and this library is not meant to solve all of them. So, it's essential to identify your app's specific needs and if this library falls short on meeting them, don't worry. You can create the necessary abstractions when the time comes, and we're confident that by then, you'll have the experience and inspiration to do so with our source code as a helpful reference. 20 | 21 | ## Installation 22 | 23 | If [available in Hex](https://hex.pm/docs/publish), the package can be installed 24 | by adding `swish` to your list of dependencies in `mix.exs`: 25 | 26 | ```elixir 27 | def deps do 28 | [ 29 | {:swish, "~> 0.1.0"} 30 | ] 31 | end 32 | ``` 33 | 34 | If you are using a different building mechanism than the default esbuild configuration... 35 | Add the following line to your application's `package.json` to make the js dependency available: 36 | 37 | ```json 38 | "dependencies": { 39 | "swish": "file:../deps/swish" 40 | } 41 | ``` 42 | 43 | Add the Swish hooks to your application's `app.js` 44 | 45 | ```js 46 | import SwishHooks from "swish"; 47 | let liveSocket = new LiveSocket("/live", Socket, {params: {_csrf_token: csrfToken}, hooks: { ...SwishHooks }}) 48 | ``` 49 | -------------------------------------------------------------------------------- /priv/static/swish.esm.js: -------------------------------------------------------------------------------- 1 | // utils/attribute.js 2 | function getAttributeOrThrow(element, attr, transform = null) { 3 | if (!element.hasAttribute(attr)) { 4 | throw new Error(`Missing attribute '${attr}' on element <${element.tagName}:${element.id}>`); 5 | } 6 | const value = element.getAttribute(attr); 7 | return transform ? transform(value) : value; 8 | } 9 | function parseInteger(value) { 10 | const number = parseInt(value, 10); 11 | if (Number.isNaN(number)) { 12 | throw new Error(`Invalid integer value ${value}`); 13 | } 14 | return number; 15 | } 16 | 17 | // hooks/portal.js 18 | var events = Object.keys(window).filter((k) => /\bon/.test(k)); 19 | function forwardEvents(template, portal) { 20 | for (const event of events) { 21 | portal.addEventListener(event, (e) => { 22 | e.stopPropagation(); 23 | template.dispatchEvent(new e.constructor(e.type, e)); 24 | }); 25 | } 26 | } 27 | var updates = { 28 | "prepend": (target, clone) => { 29 | target.parentNode.insertBefore(clone, target); 30 | }, 31 | "append": (target, clone) => { 32 | target.parentNode.insertBefore(clone, target.nextSibling); 33 | }, 34 | "origin": (target, clone) => { 35 | target.appendChild(clone); 36 | } 37 | }; 38 | var portal_default = { 39 | clone: null, 40 | target: null, 41 | update: null, 42 | closeDelay: null, 43 | closeTimeout: null, 44 | mounted() { 45 | const targetSelector = getAttributeOrThrow(this.el, "data-target"); 46 | this.target = document.querySelector(targetSelector); 47 | this.update = getAttributeOrThrow(this.el, "data-update"); 48 | this.closeDelay = getAttributeOrThrow(this.el, "data-close-delay", parseInteger); 49 | this.el.addEventListener("portal:open", this.handleOpen.bind(this)); 50 | this.el.addEventListener("portal:close", this.handleClose.bind(this)); 51 | }, 52 | destroyed() { 53 | this.clone.remove(); 54 | clearTimeout(this.closeTimeout); 55 | }, 56 | handleOpen() { 57 | this.clone = this.el.content.cloneNode(true).firstElementChild; 58 | updates[this.update](this.target, this.clone); 59 | forwardEvents(this.el, this.clone); 60 | }, 61 | handleClose() { 62 | const clone = this.clone; 63 | this.closeTimeout = setTimeout(() => clone.remove(), this.closeDelay); 64 | } 65 | }; 66 | 67 | // hooks/index.js 68 | var hooks_default = { 69 | "Swish.Portal": portal_default 70 | }; 71 | 72 | // index.js 73 | var assets_default = { 74 | Hooks: hooks_default 75 | }; 76 | export { 77 | assets_default as default 78 | }; 79 | //# sourceMappingURL=swish.esm.js.map 80 | -------------------------------------------------------------------------------- /priv/static/swish.cjs.js: -------------------------------------------------------------------------------- 1 | var __defProp = Object.defineProperty; 2 | var __markAsModule = (target) => __defProp(target, "__esModule", { value: true }); 3 | var __export = (target, all) => { 4 | __markAsModule(target); 5 | for (var name in all) 6 | __defProp(target, name, { get: all[name], enumerable: true }); 7 | }; 8 | 9 | // index.js 10 | __export(exports, { 11 | default: () => assets_default 12 | }); 13 | 14 | // utils/attribute.js 15 | function getAttributeOrThrow(element, attr, transform = null) { 16 | if (!element.hasAttribute(attr)) { 17 | throw new Error(`Missing attribute '${attr}' on element <${element.tagName}:${element.id}>`); 18 | } 19 | const value = element.getAttribute(attr); 20 | return transform ? transform(value) : value; 21 | } 22 | function parseInteger(value) { 23 | const number = parseInt(value, 10); 24 | if (Number.isNaN(number)) { 25 | throw new Error(`Invalid integer value ${value}`); 26 | } 27 | return number; 28 | } 29 | 30 | // hooks/portal.js 31 | var events = Object.keys(window).filter((k) => /\bon/.test(k)); 32 | function forwardEvents(template, portal) { 33 | for (const event of events) { 34 | portal.addEventListener(event, (e) => { 35 | e.stopPropagation(); 36 | template.dispatchEvent(new e.constructor(e.type, e)); 37 | }); 38 | } 39 | } 40 | var updates = { 41 | "prepend": (target, clone) => { 42 | target.parentNode.insertBefore(clone, target); 43 | }, 44 | "append": (target, clone) => { 45 | target.parentNode.insertBefore(clone, target.nextSibling); 46 | }, 47 | "origin": (target, clone) => { 48 | target.appendChild(clone); 49 | } 50 | }; 51 | var portal_default = { 52 | clone: null, 53 | target: null, 54 | update: null, 55 | closeDelay: null, 56 | closeTimeout: null, 57 | mounted() { 58 | const targetSelector = getAttributeOrThrow(this.el, "data-target"); 59 | this.target = document.querySelector(targetSelector); 60 | this.update = getAttributeOrThrow(this.el, "data-update"); 61 | this.closeDelay = getAttributeOrThrow(this.el, "data-close-delay", parseInteger); 62 | this.el.addEventListener("portal:open", this.handleOpen.bind(this)); 63 | this.el.addEventListener("portal:close", this.handleClose.bind(this)); 64 | }, 65 | destroyed() { 66 | this.clone.remove(); 67 | clearTimeout(this.closeTimeout); 68 | }, 69 | handleOpen() { 70 | this.clone = this.el.content.cloneNode(true).firstElementChild; 71 | updates[this.update](this.target, this.clone); 72 | forwardEvents(this.el, this.clone); 73 | }, 74 | handleClose() { 75 | const clone = this.clone; 76 | this.closeTimeout = setTimeout(() => clone.remove(), this.closeDelay); 77 | } 78 | }; 79 | 80 | // hooks/index.js 81 | var hooks_default = { 82 | "Swish.Portal": portal_default 83 | }; 84 | 85 | // index.js 86 | var assets_default = { 87 | Hooks: hooks_default 88 | }; 89 | //# sourceMappingURL=swish.cjs.js.map 90 | -------------------------------------------------------------------------------- /lib/swish/js.ex: -------------------------------------------------------------------------------- 1 | defmodule Swish.JS do 2 | @moduledoc """ 3 | Defines the behaviour for JS commands used by Swish components in your application. 4 | 5 | Although this module provides a default implementation for most commands used by the library, 6 | the user is encouraged to customize it by creating its implementations if necessary. 7 | """ 8 | 9 | alias Phoenix.LiveView.JS 10 | 11 | @callback show_dialog(JS.t(), Swish.Dialog.t()) :: JS.t() 12 | @callback hide_dialog(JS.t(), Swish.Dialog.t()) :: JS.t() 13 | 14 | @doc false 15 | def dynamic! do 16 | Application.fetch_env!(:swish, :js) 17 | end 18 | 19 | defmacro __using__(_opts) do 20 | quote do 21 | @behaviour Swish.JS 22 | 23 | def show_dialog(js \\ %JS{}, %Swish.Dialog{} = dialog) do 24 | trigger_target = Swish.EL.suffix_id(dialog, "trigger", true) 25 | backdrop_target = Swish.EL.suffix_id(dialog, "backdrop", true) 26 | content_target = Swish.EL.suffix_id(dialog, "content", true) 27 | 28 | js 29 | |> JS.dispatch("portal:open", to: "##{dialog.portal_id}") 30 | |> JS.set_attribute({"data-state", "open"}, to: trigger_target) 31 | |> JS.set_attribute({"data-state", "open"}, to: backdrop_target) 32 | |> JS.set_attribute({"data-state", "open"}, to: content_target) 33 | |> JS.set_attribute({"aria-expanded", "true"}, to: trigger_target) 34 | |> JS.show( 35 | to: backdrop_target, 36 | transition: dialog.transitions.show_backdrop, 37 | time: dialog.open_delay 38 | ) 39 | |> JS.show( 40 | to: content_target, 41 | transition: dialog.transitions.show_content, 42 | time: dialog.open_delay 43 | ) 44 | |> JS.focus_first(to: content_target) 45 | end 46 | 47 | def hide_dialog(js \\ %JS{}, %Swish.Dialog{} = dialog) do 48 | trigger_target = Swish.EL.suffix_id(dialog, "trigger", true) 49 | backdrop_target = Swish.EL.suffix_id(dialog, "backdrop", true) 50 | content_target = Swish.EL.suffix_id(dialog, "content", true) 51 | 52 | js 53 | |> JS.pop_focus() 54 | |> JS.hide( 55 | to: "##{dialog.id}-backdrop", 56 | transition: dialog.transitions.hide_backdrop, 57 | time: dialog.close_delay 58 | ) 59 | |> JS.hide( 60 | to: "##{dialog.id}-content", 61 | transition: dialog.transitions.hide_content, 62 | time: dialog.close_delay 63 | ) 64 | |> JS.set_attribute({"data-state", "closed"}, to: trigger_target) 65 | |> JS.set_attribute({"data-state", "closed"}, to: backdrop_target) 66 | |> JS.set_attribute({"data-state", "closed"}, to: content_target) 67 | |> JS.set_attribute({"aria-expanded", "false"}, to: trigger_target) 68 | |> JS.dispatch("portal:close", to: "##{dialog.portal_id}") 69 | end 70 | 71 | defoverridable Swish.JS 72 | end 73 | end 74 | end 75 | -------------------------------------------------------------------------------- /priv/static/swish.js: -------------------------------------------------------------------------------- 1 | var LiveView = (() => { 2 | var __defProp = Object.defineProperty; 3 | var __markAsModule = (target) => __defProp(target, "__esModule", { value: true }); 4 | var __export = (target, all) => { 5 | __markAsModule(target); 6 | for (var name in all) 7 | __defProp(target, name, { get: all[name], enumerable: true }); 8 | }; 9 | 10 | // index.js 11 | var assets_exports = {}; 12 | __export(assets_exports, { 13 | default: () => assets_default 14 | }); 15 | 16 | // utils/attribute.js 17 | function getAttributeOrThrow(element, attr, transform = null) { 18 | if (!element.hasAttribute(attr)) { 19 | throw new Error(`Missing attribute '${attr}' on element <${element.tagName}:${element.id}>`); 20 | } 21 | const value = element.getAttribute(attr); 22 | return transform ? transform(value) : value; 23 | } 24 | function parseInteger(value) { 25 | const number = parseInt(value, 10); 26 | if (Number.isNaN(number)) { 27 | throw new Error(`Invalid integer value ${value}`); 28 | } 29 | return number; 30 | } 31 | 32 | // hooks/portal.js 33 | var events = Object.keys(window).filter((k) => /\bon/.test(k)); 34 | function forwardEvents(template, portal) { 35 | for (const event of events) { 36 | portal.addEventListener(event, (e) => { 37 | e.stopPropagation(); 38 | template.dispatchEvent(new e.constructor(e.type, e)); 39 | }); 40 | } 41 | } 42 | var updates = { 43 | "prepend": (target, clone) => { 44 | target.parentNode.insertBefore(clone, target); 45 | }, 46 | "append": (target, clone) => { 47 | target.parentNode.insertBefore(clone, target.nextSibling); 48 | }, 49 | "origin": (target, clone) => { 50 | target.appendChild(clone); 51 | } 52 | }; 53 | var portal_default = { 54 | clone: null, 55 | target: null, 56 | update: null, 57 | closeDelay: null, 58 | closeTimeout: null, 59 | mounted() { 60 | const targetSelector = getAttributeOrThrow(this.el, "data-target"); 61 | this.target = document.querySelector(targetSelector); 62 | this.update = getAttributeOrThrow(this.el, "data-update"); 63 | this.closeDelay = getAttributeOrThrow(this.el, "data-close-delay", parseInteger); 64 | this.el.addEventListener("portal:open", this.handleOpen.bind(this)); 65 | this.el.addEventListener("portal:close", this.handleClose.bind(this)); 66 | }, 67 | destroyed() { 68 | this.clone.remove(); 69 | clearTimeout(this.closeTimeout); 70 | }, 71 | handleOpen() { 72 | this.clone = this.el.content.cloneNode(true).firstElementChild; 73 | updates[this.update](this.target, this.clone); 74 | forwardEvents(this.el, this.clone); 75 | }, 76 | handleClose() { 77 | const clone = this.clone; 78 | this.closeTimeout = setTimeout(() => clone.remove(), this.closeDelay); 79 | } 80 | }; 81 | 82 | // hooks/index.js 83 | var hooks_default = { 84 | "Swish.Portal": portal_default 85 | }; 86 | 87 | // index.js 88 | var assets_default = { 89 | Hooks: hooks_default 90 | }; 91 | return assets_exports; 92 | })(); 93 | -------------------------------------------------------------------------------- /assets/hooks/portal.js: -------------------------------------------------------------------------------- 1 | import { getAttributeOrThrow, parseInteger } from "../utils/attribute" 2 | 3 | /** 4 | * A hook used to create a Portal in the DOM. 5 | * 6 | * Portals give us the ability to render components outside the DOM hierarchy of their parent components. 7 | * This can be achieved using techniques such as creating a new HTML element outside the normal DOM hierarchy. 8 | * It also facilitates the placement of positioned that can be styled without being constrained by their parent components. 9 | * In essence, it allows the developers to create more flexible and powerful user interfaces, such as modal dialogs, tooltips, and popovers. 10 | * 11 | * ## Configuration 12 | * 13 | * * `data-update` - the operation to be executed, it can be either: origin (default), append or prepend. 14 | * * `data-target` - the DOM element where the portal is going to be placed. 15 | * * `data-close-delay` - delay in ms to close the open portal. 16 | */ 17 | 18 | // Cache a list of possible DOM events that we want to forward 19 | const events = Object.keys(window).filter((k) => /\bon/.test(k)) 20 | 21 | function forwardEvents(template, portal) { 22 | for (const event of events) { 23 | portal.addEventListener(event, e => { 24 | e.stopPropagation(); 25 | template.dispatchEvent(new e.constructor(e.type, e)); 26 | }); 27 | } 28 | } 29 | 30 | const updates = { 31 | "prepend": (target, clone) => { 32 | target.parentNode.insertBefore(clone, target) 33 | }, 34 | "append": (target, clone) => { 35 | target.parentNode.insertBefore(clone, target.nextSibling) 36 | }, 37 | "origin": (target, clone) => { 38 | target.appendChild(clone) 39 | } 40 | } 41 | 42 | export default { 43 | clone: null, 44 | target: null, 45 | update: null, 46 | closeDelay: null, 47 | closeTimeout: null, 48 | 49 | mounted() { 50 | const targetSelector = getAttributeOrThrow(this.el, "data-target"); 51 | 52 | this.target = document.querySelector(targetSelector); 53 | this.update = getAttributeOrThrow(this.el, "data-update"); 54 | this.closeDelay = getAttributeOrThrow(this.el, "data-close-delay", parseInteger); 55 | 56 | this.el.addEventListener("portal:open", this.handleOpen.bind(this)); 57 | this.el.addEventListener("portal:close", this.handleClose.bind(this)); 58 | }, 59 | 60 | destroyed() { 61 | this.clone.remove(); 62 | 63 | // Removes the timeouts just to be sure 64 | clearTimeout(this.closeTimeout); 65 | }, 66 | 67 | handleOpen() { 68 | this.clone = this.el.content.cloneNode(true).firstElementChild; 69 | 70 | // Opens the portal and teleports clone to target. 71 | // Await a little before opening so animation ca be properly displayed. 72 | updates[this.update](this.target, this.clone); 73 | 74 | // Await until next tick to register the forwarded events 75 | forwardEvents(this.el, this.clone) 76 | }, 77 | 78 | handleClose() { 79 | // Cache old clone to avoid race conditions 80 | const clone = this.clone 81 | 82 | // Closes the portal and removes the cloned element. 83 | // Await a little before closing so animations can be properly displayed. 84 | this.closeTimeout = setTimeout(() => clone.remove(), this.closeDelay); 85 | }, 86 | } 87 | -------------------------------------------------------------------------------- /lib/swish/tag.ex: -------------------------------------------------------------------------------- 1 | defmodule Swish.Tag do 2 | use Phoenix.Component 3 | 4 | @input_types ~w(checkbox color date datetime-local email file hidden month number password 5 | range radio search tel text time url week) 6 | 7 | attr(:for, :string, default: nil) 8 | slot(:inner_block, required: false) 9 | attr(:rest, :global) 10 | 11 | def label(assigns) do 12 | ~H""" 13 | 16 | """ 17 | end 18 | 19 | attr(:id, :any, default: nil) 20 | attr(:name, :any, default: nil) 21 | attr(:value, :any, default: nil) 22 | attr(:type, :string, default: "text", values: @input_types) 23 | attr(:checked, :boolean, required: false) 24 | attr(:checked_value, :any, default: true) 25 | attr(:hidden_input, :boolean, default: true) 26 | attr(:unchecked_value, :any, default: false) 27 | attr(:multiple, :boolean, default: false) 28 | attr(:rest, :global) 29 | 30 | def input(assigns) do 31 | assigns 32 | |> update(:id, &(&1.id || &1.name)) 33 | |> update(:name, &(&1.multiple && "#{&1.name}[]")) 34 | |> update(:value, &Phoenix.HTML.Form.normalize_value("checkbox", &1.value)) 35 | |> render_input() 36 | end 37 | 38 | attr(:id, :any, default: nil) 39 | attr(:name, :any, default: nil) 40 | attr(:value, :any, default: nil) 41 | attr(:multiple, :boolean, default: false) 42 | attr(:rest, :global) 43 | 44 | def textarea(assigns) do 45 | assigns = 46 | assigns 47 | |> update(:id, &(&1.id || &1.name)) 48 | |> update(:name, &(&1.multiple && "#{&1.name}[]")) 49 | |> update(:value, &Phoenix.HTML.Form.normalize_value("checkbox", &1.value)) 50 | 51 | ~H""" 52 | 53 | """ 54 | end 55 | 56 | attr(:id, :any, default: nil) 57 | attr(:name, :any, default: nil) 58 | attr(:value, :any, default: nil) 59 | attr(:options, :list, default: []) 60 | attr(:prompt, :string, default: nil) 61 | attr(:multiple, :boolean, default: false) 62 | attr(:rest, :global) 63 | 64 | def select(assigns) do 65 | assigns = 66 | assigns 67 | |> update(:id, &(&1.id || &1.name)) 68 | |> update(:name, &(&1.multiple && "#{&1.name}[]")) 69 | |> update(:value, &Phoenix.HTML.Form.normalize_value("checkbox", &1.value)) 70 | 71 | ~H""" 72 | 76 | """ 77 | end 78 | 79 | attr(:id, :string, required: true) 80 | attr(:target, :string, default: "body") 81 | attr(:update, :string, values: ~w(prepend append origin), default: "origin") 82 | attr(:close_delay, :integer, default: 0) 83 | attr(:rest, :global) 84 | slot(:inner_block, required: true) 85 | 86 | def portal(assigns) do 87 | ~H""" 88 | 98 | """ 99 | end 100 | 101 | defp render_input(%{type: "checkbox"} = assigns) do 102 | ~H""" 103 | 104 | 105 | """ 106 | end 107 | 108 | defp render_input(assigns) do 109 | ~H""" 110 | 111 | """ 112 | end 113 | end 114 | -------------------------------------------------------------------------------- /lib/swish/form.ex: -------------------------------------------------------------------------------- 1 | defmodule Swish.Form do 2 | use Phoenix.Component 3 | 4 | @doc """ 5 | Renders a form component. 6 | 7 | ## Examples 8 | 9 | #### Simple form control 10 | 11 | ```heex 12 | 13 | 14 | 15 | 16 | 17 | <%= error %> 18 | 19 | 20 | 21 | ``` 22 | """ 23 | attr(:for, :any, required: true) 24 | attr(:as, :any, default: nil) 25 | slot(:inner_block, required: true) 26 | attr(:rest, :global) 27 | 28 | def root(assigns) do 29 | ~H""" 30 | <.form :let={f} for={@for} as={@as} {@rest}> 31 | <%= render_slot(@inner_block, f) %> 32 | 33 | """ 34 | end 35 | 36 | @doc """ 37 | Renders a form group component. 38 | 39 | ## Examples 40 | 41 | #### Simple form group 42 | 43 | ```heex 44 | 45 | 46 | 47 | ``` 48 | """ 49 | attr(:field, Phoenix.HTML.FormField, required: true) 50 | attr(:name, :string, required: false) 51 | slot(:inner_block, required: true) 52 | attr(:rest, :global) 53 | 54 | def group(assigns) do 55 | assigns = assign_new(assigns, :name, & &1.field.name) 56 | 57 | ~H""" 58 |
59 | <%= render_slot(@inner_block) %> 60 |
61 | """ 62 | end 63 | 64 | @doc """ 65 | Renders a form control component. 66 | 67 | ## Examples 68 | 69 | #### Simple form control 70 | 71 | ```heex 72 | 73 | 74 | 75 | 76 | ``` 77 | """ 78 | 79 | attr(:field, Phoenix.HTML.FormField, required: true) 80 | attr(:as, :string, default: "text") 81 | attr(:rest, :global) 82 | 83 | def control(assigns) do 84 | assigns 85 | |> assign_new(:id, & &1.field.id) 86 | |> assign_new(:name, & &1.field.name) 87 | |> assign_new(:value, & &1.field.value) 88 | |> render_control() 89 | end 90 | 91 | @doc """ 92 | Renders a label component. 93 | 94 | ## Examples 95 | 96 | #### Simple label 97 | 98 | ```heex 99 | 100 | ``` 101 | 102 | #### Custom content 103 | 104 | ```heex 105 | 106 | Name 107 | 108 | ``` 109 | """ 110 | 111 | attr(:field, Phoenix.HTML.FormField, required: true) 112 | attr(:label, :string, required: false) 113 | slot(:inner_block, required: false) 114 | attr(:rest, :global) 115 | 116 | def label(assigns) do 117 | assigns = 118 | assigns 119 | |> assign_new(:for, & &1.field.id) 120 | |> assign_new(:label, &Phoenix.Naming.humanize(&1.field.name)) 121 | 122 | ~H""" 123 | 124 | <%= (@innner_block != [] && render_slot(@inner_block)) || @label %> 125 | 126 | """ 127 | end 128 | 129 | @doc """ 130 | Renders a message component. 131 | 132 | ## Examples 133 | 134 | #### Simple message 135 | 136 | ```heex 137 | 138 | ... 139 | 140 | ``` 141 | 142 | #### Custom tag 143 | 144 | ```heex 145 | 146 | ... 147 | 148 | ``` 149 | """ 150 | 151 | attr(:field, Phoenix.HTML.FormField, required: true) 152 | attr(:as, :string, default: "p") 153 | slot(:inner_block, required: true) 154 | attr(:rest, :global) 155 | 156 | def message(assigns) do 157 | assigns = assign_new(assigns, :errors, &Enum.map(&1, translate_error(&1))) 158 | 159 | ~H""" 160 | <.dynamic_tag name={@as} {@rest}> 161 | <%= render_slot(@inner_block, @errors) %> 162 | 163 | """ 164 | end 165 | 166 | defp render_control(%{as: "textarea"} = assigns) do 167 | ~H""" 168 | 169 | """ 170 | end 171 | 172 | defp render_control(%{as: "select"} = assigns) do 173 | ~H""" 174 | 175 | """ 176 | end 177 | 178 | defp render_control(assigns) do 179 | ~H""" 180 | 181 | """ 182 | end 183 | 184 | def translate_error({msg, opts}) do 185 | module = Application.get_env(:swish, :gettext) 186 | 187 | case {module, opts[:count]} do 188 | {nil, _} -> msg 189 | {module, nil} -> Gettext.dgettext(module, "errors", msg, opts) 190 | {module, count} -> Gettext.dngettext(module, "errors", msg, msg, count, opts) 191 | end 192 | end 193 | end 194 | -------------------------------------------------------------------------------- /priv/static/swish.esm.js.map: -------------------------------------------------------------------------------- 1 | { 2 | "version": 3, 3 | "sources": ["../../assets/utils/attribute.js", "../../assets/hooks/portal.js", "../../assets/hooks/index.js", "../../assets/index.js"], 4 | "sourcesContent": ["export function getAttributeOrThrow(element, attr, transform = null) {\n if (!element.hasAttribute(attr)) {\n throw new Error(\n `Missing attribute '${attr}' on element <${element.tagName}:${element.id}>`\n );\n }\n\n const value = element.getAttribute(attr);\n\n return transform ? transform(value) : value;\n}\n\nexport function getAttributeOrDefault(\n element,\n attr,\n defaultValue,\n transform = null\n) {\n if (element.hasAttribute(attr)) {\n const value = element.getAttribute(attr);\n return transform ? transform(value) : value;\n } else {\n return defaultValue;\n }\n}\n\nexport function getElementAttributeOrThrow(element, type, attr) {\n if (!(element instanceof type)) throw new Error(`Element is not of type '${type}'`);\n return getAttributeOrThrow(element, attr);\n}\n\nexport function parseBoolean(value) {\n if (value === \"true\") {\n return true;\n }\n\n if (value === \"false\") {\n return false;\n }\n\n throw new Error(\n `Invalid boolean attribute ${value}, should be either \"true\" or \"false\"`\n );\n}\n\nexport function parseInteger(value) {\n const number = parseInt(value, 10);\n\n if (Number.isNaN(number)) {\n throw new Error(`Invalid integer value ${value}`);\n }\n\n return number;\n}", "import { getAttributeOrThrow, parseInteger } from \"../utils/attribute\"\n\n/**\n * A hook used to create a Portal in the DOM.\n * \n * Portals give us the ability to render components outside the DOM hierarchy of their parent components. \n * This can be achieved using techniques such as creating a new HTML element outside the normal DOM hierarchy.\n * It also facilitates the placement of positioned that can be styled without being constrained by their parent components. \n * In essence, it allows the developers to create more flexible and powerful user interfaces, such as modal dialogs, tooltips, and popovers.\n * \n * ## Configuration\n * \n * * `data-update` - the operation to be executed, it can be either: origin (default), append or prepend.\n * * `data-target` - the DOM element where the portal is going to be placed. \n * * `data-close-delay` - delay in ms to close the open portal.\n */\n\n// Cache a list of possible DOM events that we want to forward\nconst events = Object.keys(window).filter((k) => /\\bon/.test(k))\n\nfunction forwardEvents(template, portal) {\n for (const event of events) {\n portal.addEventListener(event, e => {\n e.stopPropagation();\n template.dispatchEvent(new e.constructor(e.type, e));\n });\n }\n}\n\nconst updates = {\n \"prepend\": (target, clone) => {\n target.parentNode.insertBefore(clone, target)\n },\n \"append\": (target, clone) => {\n target.parentNode.insertBefore(clone, target.nextSibling)\n },\n \"origin\": (target, clone) => {\n target.appendChild(clone)\n }\n}\n\nexport default {\n clone: null,\n target: null,\n update: null,\n closeDelay: null,\n closeTimeout: null,\n\n mounted() {\n const targetSelector = getAttributeOrThrow(this.el, \"data-target\");\n\n this.target = document.querySelector(targetSelector);\n this.update = getAttributeOrThrow(this.el, \"data-update\");\n this.closeDelay = getAttributeOrThrow(this.el, \"data-close-delay\", parseInteger);\n\n this.el.addEventListener(\"portal:open\", this.handleOpen.bind(this));\n this.el.addEventListener(\"portal:close\", this.handleClose.bind(this));\n },\n\n destroyed() {\n this.clone.remove();\n\n // Removes the timeouts just to be sure \n clearTimeout(this.closeTimeout);\n },\n\n handleOpen() {\n this.clone = this.el.content.cloneNode(true).firstElementChild;\n\n // Opens the portal and teleports clone to target.\n // Await a little before opening so animation ca be properly displayed.\n updates[this.update](this.target, this.clone);\n\n // Await until next tick to register the forwarded events\n forwardEvents(this.el, this.clone)\n },\n\n handleClose() {\n // Cache old clone to avoid race conditions\n const clone = this.clone\n\n // Closes the portal and removes the cloned element.\n // Await a little before closing so animations can be properly displayed. \n this.closeTimeout = setTimeout(() => clone.remove(), this.closeDelay);\n },\n}\n", "import Portal from \"./portal\";\n\nexport default {\n \"Swish.Portal\": Portal\n}\n", "\nimport Hooks from \"./hooks\";\n\nexport default {\n\tHooks\n}\n"], 5 | "mappings": ";AAAO,6BAA6B,SAAS,MAAM,YAAY,MAAM;AACnE,MAAI,CAAC,QAAQ,aAAa,OAAO;AAC/B,UAAM,IAAI,MACR,sBAAsB,qBAAqB,QAAQ,WAAW,QAAQ;AAAA;AAI1E,QAAM,QAAQ,QAAQ,aAAa;AAEnC,SAAO,YAAY,UAAU,SAAS;AAAA;AAoCjC,sBAAsB,OAAO;AAClC,QAAM,SAAS,SAAS,OAAO;AAE/B,MAAI,OAAO,MAAM,SAAS;AACxB,UAAM,IAAI,MAAM,yBAAyB;AAAA;AAG3C,SAAO;AAAA;;;AClCT,IAAM,SAAS,OAAO,KAAK,QAAQ,OAAO,CAAC,MAAM,OAAO,KAAK;AAE7D,uBAAuB,UAAU,QAAQ;AACvC,aAAW,SAAS,QAAQ;AAC1B,WAAO,iBAAiB,OAAO,OAAK;AAClC,QAAE;AACF,eAAS,cAAc,IAAI,EAAE,YAAY,EAAE,MAAM;AAAA;AAAA;AAAA;AAKvD,IAAM,UAAU;AAAA,EACd,WAAW,CAAC,QAAQ,UAAU;AAC5B,WAAO,WAAW,aAAa,OAAO;AAAA;AAAA,EAExC,UAAU,CAAC,QAAQ,UAAU;AAC3B,WAAO,WAAW,aAAa,OAAO,OAAO;AAAA;AAAA,EAE/C,UAAU,CAAC,QAAQ,UAAU;AAC3B,WAAO,YAAY;AAAA;AAAA;AAIvB,IAAO,iBAAQ;AAAA,EACb,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,YAAY;AAAA,EACZ,cAAc;AAAA,EAEd,UAAU;AACR,UAAM,iBAAiB,oBAAoB,KAAK,IAAI;AAEpD,SAAK,SAAS,SAAS,cAAc;AACrC,SAAK,SAAS,oBAAoB,KAAK,IAAI;AAC3C,SAAK,aAAa,oBAAoB,KAAK,IAAI,oBAAoB;AAEnE,SAAK,GAAG,iBAAiB,eAAe,KAAK,WAAW,KAAK;AAC7D,SAAK,GAAG,iBAAiB,gBAAgB,KAAK,YAAY,KAAK;AAAA;AAAA,EAGjE,YAAY;AACV,SAAK,MAAM;AAGX,iBAAa,KAAK;AAAA;AAAA,EAGpB,aAAa;AACX,SAAK,QAAQ,KAAK,GAAG,QAAQ,UAAU,MAAM;AAI7C,YAAQ,KAAK,QAAQ,KAAK,QAAQ,KAAK;AAGvC,kBAAc,KAAK,IAAI,KAAK;AAAA;AAAA,EAG9B,cAAc;AAEZ,UAAM,QAAQ,KAAK;AAInB,SAAK,eAAe,WAAW,MAAM,MAAM,UAAU,KAAK;AAAA;AAAA;;;ACjF9D,IAAO,gBAAQ;AAAA,EACb,gBAAgB;AAAA;;;ACAlB,IAAO,iBAAQ;AAAA,EACd;AAAA;", 6 | "names": [] 7 | } 8 | -------------------------------------------------------------------------------- /priv/static/swish.cjs.js.map: -------------------------------------------------------------------------------- 1 | { 2 | "version": 3, 3 | "sources": ["../../assets/index.js", "../../assets/utils/attribute.js", "../../assets/hooks/portal.js", "../../assets/hooks/index.js"], 4 | "sourcesContent": ["\nimport Hooks from \"./hooks\";\n\nexport default {\n\tHooks\n}\n", "export function getAttributeOrThrow(element, attr, transform = null) {\n if (!element.hasAttribute(attr)) {\n throw new Error(\n `Missing attribute '${attr}' on element <${element.tagName}:${element.id}>`\n );\n }\n\n const value = element.getAttribute(attr);\n\n return transform ? transform(value) : value;\n}\n\nexport function getAttributeOrDefault(\n element,\n attr,\n defaultValue,\n transform = null\n) {\n if (element.hasAttribute(attr)) {\n const value = element.getAttribute(attr);\n return transform ? transform(value) : value;\n } else {\n return defaultValue;\n }\n}\n\nexport function getElementAttributeOrThrow(element, type, attr) {\n if (!(element instanceof type)) throw new Error(`Element is not of type '${type}'`);\n return getAttributeOrThrow(element, attr);\n}\n\nexport function parseBoolean(value) {\n if (value === \"true\") {\n return true;\n }\n\n if (value === \"false\") {\n return false;\n }\n\n throw new Error(\n `Invalid boolean attribute ${value}, should be either \"true\" or \"false\"`\n );\n}\n\nexport function parseInteger(value) {\n const number = parseInt(value, 10);\n\n if (Number.isNaN(number)) {\n throw new Error(`Invalid integer value ${value}`);\n }\n\n return number;\n}", "import { getAttributeOrThrow, parseInteger } from \"../utils/attribute\"\n\n/**\n * A hook used to create a Portal in the DOM.\n * \n * Portals give us the ability to render components outside the DOM hierarchy of their parent components. \n * This can be achieved using techniques such as creating a new HTML element outside the normal DOM hierarchy.\n * It also facilitates the placement of positioned that can be styled without being constrained by their parent components. \n * In essence, it allows the developers to create more flexible and powerful user interfaces, such as modal dialogs, tooltips, and popovers.\n * \n * ## Configuration\n * \n * * `data-update` - the operation to be executed, it can be either: origin (default), append or prepend.\n * * `data-target` - the DOM element where the portal is going to be placed. \n * * `data-close-delay` - delay in ms to close the open portal.\n */\n\n// Cache a list of possible DOM events that we want to forward\nconst events = Object.keys(window).filter((k) => /\\bon/.test(k))\n\nfunction forwardEvents(template, portal) {\n for (const event of events) {\n portal.addEventListener(event, e => {\n e.stopPropagation();\n template.dispatchEvent(new e.constructor(e.type, e));\n });\n }\n}\n\nconst updates = {\n \"prepend\": (target, clone) => {\n target.parentNode.insertBefore(clone, target)\n },\n \"append\": (target, clone) => {\n target.parentNode.insertBefore(clone, target.nextSibling)\n },\n \"origin\": (target, clone) => {\n target.appendChild(clone)\n }\n}\n\nexport default {\n clone: null,\n target: null,\n update: null,\n closeDelay: null,\n closeTimeout: null,\n\n mounted() {\n const targetSelector = getAttributeOrThrow(this.el, \"data-target\");\n\n this.target = document.querySelector(targetSelector);\n this.update = getAttributeOrThrow(this.el, \"data-update\");\n this.closeDelay = getAttributeOrThrow(this.el, \"data-close-delay\", parseInteger);\n\n this.el.addEventListener(\"portal:open\", this.handleOpen.bind(this));\n this.el.addEventListener(\"portal:close\", this.handleClose.bind(this));\n },\n\n destroyed() {\n this.clone.remove();\n\n // Removes the timeouts just to be sure \n clearTimeout(this.closeTimeout);\n },\n\n handleOpen() {\n this.clone = this.el.content.cloneNode(true).firstElementChild;\n\n // Opens the portal and teleports clone to target.\n // Await a little before opening so animation ca be properly displayed.\n updates[this.update](this.target, this.clone);\n\n // Await until next tick to register the forwarded events\n forwardEvents(this.el, this.clone)\n },\n\n handleClose() {\n // Cache old clone to avoid race conditions\n const clone = this.clone\n\n // Closes the portal and removes the cloned element.\n // Await a little before closing so animations can be properly displayed. \n this.closeTimeout = setTimeout(() => clone.remove(), this.closeDelay);\n },\n}\n", "import Portal from \"./portal\";\n\nexport default {\n \"Swish.Portal\": Portal\n}\n"], 5 | "mappings": ";;;;;;;;;AAAA;AAAA;AAAA;;;ACAO,6BAA6B,SAAS,MAAM,YAAY,MAAM;AACnE,MAAI,CAAC,QAAQ,aAAa,OAAO;AAC/B,UAAM,IAAI,MACR,sBAAsB,qBAAqB,QAAQ,WAAW,QAAQ;AAAA;AAI1E,QAAM,QAAQ,QAAQ,aAAa;AAEnC,SAAO,YAAY,UAAU,SAAS;AAAA;AAoCjC,sBAAsB,OAAO;AAClC,QAAM,SAAS,SAAS,OAAO;AAE/B,MAAI,OAAO,MAAM,SAAS;AACxB,UAAM,IAAI,MAAM,yBAAyB;AAAA;AAG3C,SAAO;AAAA;;;AClCT,IAAM,SAAS,OAAO,KAAK,QAAQ,OAAO,CAAC,MAAM,OAAO,KAAK;AAE7D,uBAAuB,UAAU,QAAQ;AACvC,aAAW,SAAS,QAAQ;AAC1B,WAAO,iBAAiB,OAAO,OAAK;AAClC,QAAE;AACF,eAAS,cAAc,IAAI,EAAE,YAAY,EAAE,MAAM;AAAA;AAAA;AAAA;AAKvD,IAAM,UAAU;AAAA,EACd,WAAW,CAAC,QAAQ,UAAU;AAC5B,WAAO,WAAW,aAAa,OAAO;AAAA;AAAA,EAExC,UAAU,CAAC,QAAQ,UAAU;AAC3B,WAAO,WAAW,aAAa,OAAO,OAAO;AAAA;AAAA,EAE/C,UAAU,CAAC,QAAQ,UAAU;AAC3B,WAAO,YAAY;AAAA;AAAA;AAIvB,IAAO,iBAAQ;AAAA,EACb,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,YAAY;AAAA,EACZ,cAAc;AAAA,EAEd,UAAU;AACR,UAAM,iBAAiB,oBAAoB,KAAK,IAAI;AAEpD,SAAK,SAAS,SAAS,cAAc;AACrC,SAAK,SAAS,oBAAoB,KAAK,IAAI;AAC3C,SAAK,aAAa,oBAAoB,KAAK,IAAI,oBAAoB;AAEnE,SAAK,GAAG,iBAAiB,eAAe,KAAK,WAAW,KAAK;AAC7D,SAAK,GAAG,iBAAiB,gBAAgB,KAAK,YAAY,KAAK;AAAA;AAAA,EAGjE,YAAY;AACV,SAAK,MAAM;AAGX,iBAAa,KAAK;AAAA;AAAA,EAGpB,aAAa;AACX,SAAK,QAAQ,KAAK,GAAG,QAAQ,UAAU,MAAM;AAI7C,YAAQ,KAAK,QAAQ,KAAK,QAAQ,KAAK;AAGvC,kBAAc,KAAK,IAAI,KAAK;AAAA;AAAA,EAG9B,cAAc;AAEZ,UAAM,QAAQ,KAAK;AAInB,SAAK,eAAe,WAAW,MAAM,MAAM,UAAU,KAAK;AAAA;AAAA;;;ACjF9D,IAAO,gBAAQ;AAAA,EACb,gBAAgB;AAAA;;;AHAlB,IAAO,iBAAQ;AAAA,EACd;AAAA;", 6 | "names": [] 7 | } 8 | -------------------------------------------------------------------------------- /mix.lock: -------------------------------------------------------------------------------- 1 | %{ 2 | "castore": {:hex, :castore, "1.0.1", "240b9edb4e9e94f8f56ab39d8d2d0a57f49e46c56aced8f873892df8ff64ff5a", [:mix], [], "hexpm", "b4951de93c224d44fac71614beabd88b71932d0b1dea80d2f80fb9044e01bbb3"}, 3 | "earmark_parser": {:hex, :earmark_parser, "1.4.31", "a93921cdc6b9b869f519213d5bc79d9e218ba768d7270d46fdcf1c01bacff9e2", [:mix], [], "hexpm", "317d367ee0335ef037a87e46c91a2269fef6306413f731e8ec11fc45a7efd059"}, 4 | "esbuild": {:hex, :esbuild, "0.7.0", "ce3afb13cd2c5fd63e13c0e2d0e0831487a97a7696cfa563707342bb825d122a", [:mix], [{:castore, ">= 0.0.0", [hex: :castore, repo: "hexpm", optional: false]}], "hexpm", "4ae9f4f237c5ebcb001390b8ada65a12fb2bb04f3fe3d1f1692b7a06fbfe8752"}, 5 | "ex_doc": {:hex, :ex_doc, "0.29.2", "dfa97532ba66910b2a3016a4bbd796f41a86fc71dd5227e96f4c8581fdf0fdf0", [:mix], [{:earmark_parser, "~> 1.4.19", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "6b5d7139eda18a753e3250e27e4a929f8d2c880dd0d460cb9986305dea3e03af"}, 6 | "expo": {:hex, :expo, "0.4.0", "bbe4bf455e2eb2ebd2f1e7d83530ce50fb9990eb88fc47855c515bfdf1c6626f", [:mix], [], "hexpm", "a8ed1683ec8b7c7fa53fd7a41b2c6935f539168a6bb0616d7fd6b58a36f3abf2"}, 7 | "gettext": {:hex, :gettext, "0.22.1", "e7942988383c3d9eed4bdc22fc63e712b655ae94a672a27e4900e3d4a2c43581", [:mix], [{:expo, "~> 0.4.0", [hex: :expo, repo: "hexpm", optional: false]}], "hexpm", "ad105b8dab668ee3f90c0d3d94ba75e9aead27a62495c101d94f2657a190ac5d"}, 8 | "makeup": {:hex, :makeup, "1.1.0", "6b67c8bc2882a6b6a445859952a602afc1a41c2e08379ca057c0f525366fc3ca", [:mix], [{:nimble_parsec, "~> 1.2.2 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "0a45ed501f4a8897f580eabf99a2e5234ea3e75a4373c8a52824f6e873be57a6"}, 9 | "makeup_elixir": {:hex, :makeup_elixir, "0.16.0", "f8c570a0d33f8039513fbccaf7108c5d750f47d8defd44088371191b76492b0b", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "28b2cbdc13960a46ae9a8858c4bebdec3c9a6d7b4b9e7f4ed1502f8159f338e7"}, 10 | "makeup_erlang": {:hex, :makeup_erlang, "0.1.1", "3fcb7f09eb9d98dc4d208f49cc955a34218fc41ff6b84df7c75b3e6e533cc65f", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "174d0809e98a4ef0b3309256cbf97101c6ec01c4ab0b23e926a9e17df2077cbb"}, 11 | "mime": {:hex, :mime, "2.0.3", "3676436d3d1f7b81b5a2d2bd8405f412c677558c81b1c92be58c00562bb59095", [:mix], [], "hexpm", "27a30bf0db44d25eecba73755acf4068cbfe26a4372f9eb3e4ea3a45956bff6b"}, 12 | "nimble_parsec": {:hex, :nimble_parsec, "1.2.3", "244836e6e3f1200c7f30cb56733fd808744eca61fd182f731eac4af635cc6d0b", [:mix], [], "hexpm", "c8d789e39b9131acf7b99291e93dae60ab48ef14a7ee9d58c6964f59efb570b0"}, 13 | "phoenix": {:hex, :phoenix, "1.7.2", "c375ffb482beb4e3d20894f84dd7920442884f5f5b70b9f4528cbe0cedefec63", [:mix], [{:castore, ">= 0.0.0", [hex: :castore, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 2.1", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:phoenix_template, "~> 1.0", [hex: :phoenix_template, repo: "hexpm", optional: false]}, {:phoenix_view, "~> 2.0", [hex: :phoenix_view, repo: "hexpm", optional: true]}, {:plug, "~> 1.14", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 2.6", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:plug_crypto, "~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}, {:websock_adapter, "~> 0.4", [hex: :websock_adapter, repo: "hexpm", optional: false]}], "hexpm", "1ebca94b32b4d0e097ab2444a9742ed8ff3361acad17365e4e6b2e79b4792159"}, 14 | "phoenix_html": {:hex, :phoenix_html, "3.3.1", "4788757e804a30baac6b3fc9695bf5562465dd3f1da8eb8460ad5b404d9a2178", [:mix], [{:plug, "~> 1.5", [hex: :plug, repo: "hexpm", optional: true]}], "hexpm", "bed1906edd4906a15fd7b412b85b05e521e1f67c9a85418c55999277e553d0d3"}, 15 | "phoenix_live_view": {:hex, :phoenix_live_view, "0.18.18", "1f38fbd7c363723f19aad1a04b5490ff3a178e37daaf6999594d5f34796c47fc", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix, "~> 1.6.15 or ~> 1.7.0", [hex: :phoenix, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 3.3", [hex: :phoenix_html, repo: "hexpm", optional: false]}, {:phoenix_template, "~> 1.0", [hex: :phoenix_template, repo: "hexpm", optional: false]}, {:phoenix_view, "~> 2.0", [hex: :phoenix_view, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.2 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "a5810d0472f3189ede6d2a95bda7f31c6113156b91784a3426cb0ab6a6d85214"}, 16 | "phoenix_pubsub": {:hex, :phoenix_pubsub, "2.1.1", "ba04e489ef03763bf28a17eb2eaddc2c20c6d217e2150a61e3298b0f4c2012b5", [:mix], [], "hexpm", "81367c6d1eea5878ad726be80808eb5a787a23dee699f96e72b1109c57cdd8d9"}, 17 | "phoenix_template": {:hex, :phoenix_template, "1.0.1", "85f79e3ad1b0180abb43f9725973e3b8c2c3354a87245f91431eec60553ed3ef", [:mix], [{:phoenix_html, "~> 2.14.2 or ~> 3.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}], "hexpm", "157dc078f6226334c91cb32c1865bf3911686f8bcd6bcff86736f6253e6993ee"}, 18 | "plug": {:hex, :plug, "1.14.1", "3148623796853ae96c628960b833bf6b6a894d6bdc8c199ef7160c41149b71f2", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.1.1 or ~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.3 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "a0e789be21a576b11ec55a0983e4e8f7c7b07d88dfb3b8da9e97767132271d40"}, 19 | "plug_crypto": {:hex, :plug_crypto, "1.2.5", "918772575e48e81e455818229bf719d4ab4181fcbf7f85b68a35620f78d89ced", [:mix], [], "hexpm", "26549a1d6345e2172eb1c233866756ae44a9609bd33ee6f99147ab3fd87fd842"}, 20 | "telemetry": {:hex, :telemetry, "1.2.1", "68fdfe8d8f05a8428483a97d7aab2f268aaff24b49e0f599faa091f1d4e7f61c", [:rebar3], [], "hexpm", "dad9ce9d8effc621708f99eac538ef1cbe05d6a874dd741de2e689c47feafed5"}, 21 | "websock": {:hex, :websock, "0.5.0", "f6bbce90226121d62a0715bca7c986c5e43de0ccc9475d79c55381d1796368cc", [:mix], [], "hexpm", "b51ac706df8a7a48a2c622ee02d09d68be8c40418698ffa909d73ae207eb5fb8"}, 22 | "websock_adapter": {:hex, :websock_adapter, "0.5.0", "cea35d8bbf1a6964e32d4b02ceb561dfb769c04f16d60d743885587e7d2ca55b", [:mix], [{:bandit, "~> 0.6", [hex: :bandit, repo: "hexpm", optional: true]}, {:plug, "~> 1.14", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 2.6", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:websock, "~> 0.5", [hex: :websock, repo: "hexpm", optional: false]}], "hexpm", "16318b124effab8209b1eb7906c636374f623dc9511a8278ad09c083cea5bb83"}, 23 | } 24 | -------------------------------------------------------------------------------- /lib/swish/dialog.ex: -------------------------------------------------------------------------------- 1 | defmodule Swish.Dialog do 2 | @moduledoc """ 3 | A dialog is a window overlaid on either the primary window or another dialog window. 4 | Windows under a modal dialog are inert. That is, users cannot interact with content outside an active dialog window. 5 | Inert content outside an active dialog is typically visually obscured or dimmed so it is difficult to discern, 6 | and in some implementations, attempts to interact with the inert content cause the dialog to close. 7 | 8 | ## ARIA design pattern 9 | https://www.w3.org/WAI/ARIA/apg/patterns/dialog-modal/ 10 | 11 | ## Markup example 12 | 13 | ```heex 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | Welcome to Swish! 22 | Swish is a UI toolkit for busy developers 23 |

Lorem ipsum dolor sit amet, qui minim labore adipisicing minim sint cillum sint consectetur cupidatat.

24 |
25 |
26 |
27 |
28 | ``` 29 | """ 30 | 31 | @type t :: %Swish.Dialog{} 32 | 33 | @enforce_keys [:id, :portal_id, :open, :static, :close_delay, :open_delay, :transitions] 34 | defstruct [ 35 | :id, 36 | :portal_id, 37 | :js_show, 38 | :js_hide, 39 | :open, 40 | :static, 41 | :close_delay, 42 | :open_delay, 43 | :transitions 44 | ] 45 | 46 | use Phoenix.Component 47 | 48 | alias __MODULE__ 49 | alias Swish.Dialog 50 | alias Phoenix.LiveView.JS 51 | 52 | @doc false 53 | def new(attrs \\ %{}) do 54 | js_module = Swish.JS.dynamic!() 55 | 56 | %Dialog{ 57 | id: attrs[:id] || Swish.EL.new_id("dialog"), 58 | open: attrs[:open] || false, 59 | static: attrs[:static] || false, 60 | open_delay: attrs[:open_delay] || 200, 61 | close_delay: attrs[:close_delay] || 200, 62 | portal_id: Swish.EL.new_id("portal"), 63 | js_show: Function.capture(js_module, :show_dialog, 2), 64 | js_hide: Function.capture(js_module, :hide_dialog, 2), 65 | transitions: attrs[:transitions] || %Dialog.Transitions{} 66 | } 67 | end 68 | 69 | attr(:id, :string, default: nil) 70 | attr(:open, :boolean, default: false) 71 | attr(:static, :boolean, default: false) 72 | attr(:open_delay, :integer, default: 200) 73 | attr(:close_delay, :integer, default: 200) 74 | attr(:transitions, Dialog.Transitions, default: %Dialog.Transitions{}) 75 | 76 | attr(:dialog, Dialog, required: false) 77 | 78 | attr(:rest, :global) 79 | slot(:inner_block, required: true) 80 | 81 | def root(assigns) do 82 | assigns = 83 | assign_new(assigns, :dialog, fn -> 84 | Dialog.new(%{ 85 | id: assigns.id, 86 | open: assigns.open, 87 | static: assigns.static, 88 | open_delay: assigns.open_delay, 89 | close_delay: assigns.close_delay, 90 | transitions: assigns.transitions 91 | }) 92 | end) 93 | 94 | ~H""" 95 |
96 | <%= render_slot(@inner_block, @dialog) %> 97 |
98 | """ 99 | end 100 | 101 | attr(:dialog, Dialog, required: true) 102 | slot(:inner_block, required: true) 103 | 104 | def trigger(assigns) do 105 | assigns = 106 | assign(assigns, :attrs, %{ 107 | aria_haspopup: "dialog", 108 | phx_click: JS.exec("data-show", to: "##{assigns.dialog.portal_id}"), 109 | id: Swish.EL.suffix_id(assigns.dialog, "trigger"), 110 | data_state: open_to_state(assigns.dialog) 111 | }) 112 | 113 | ~H""" 114 | <%= render_slot(@inner_block, @attrs) %> 115 | """ 116 | end 117 | 118 | attr(:dialog, Dialog, required: true) 119 | slot(:inner_block, required: true) 120 | attr(:rest, :global) 121 | 122 | def backdrop(assigns) do 123 | assigns = assign(assigns, id: Swish.EL.suffix_id(assigns.dialog, "backdrop")) 124 | 125 | ~H""" 126 | 135 | """ 136 | end 137 | 138 | attr(:dialog, Dialog, required: true) 139 | slot(:inner_block, required: true) 140 | 141 | def close(assigns) do 142 | assigns = 143 | assign(assigns, :attrs, %{ 144 | aria_label: "Close", 145 | phx_click: hide(assigns.dialog), 146 | id: Swish.EL.suffix_id(assigns.dialog, "close") 147 | }) 148 | 149 | ~H""" 150 | <%= render_slot(@inner_block, @attrs) %> 151 | """ 152 | end 153 | 154 | attr(:dialog, Dialog, required: true) 155 | attr(:rest, :global) 156 | slot(:inner_block, required: true) 157 | 158 | def content(assigns) do 159 | assigns = assign(assigns, id: Swish.EL.suffix_id(assigns.dialog, "content")) 160 | 161 | ~H""" 162 | <.focus_wrap 163 | id={@id} 164 | phx-key={unless @dialog.static, do: "escape"} 165 | data-hide={unless @dialog.static, do: hide(@dialog)} 166 | phx-click-away={JS.exec("data-hide")} 167 | phx-window-keydown={JS.exec("data-hide")} 168 | aria-labelledby={Swish.EL.suffix_id(@dialog, "title")} 169 | aria-describedby={Swish.EL.suffix_id(@dialog, "description")} 170 | data-state={open_to_state(@dialog)} 171 | role="dialog" 172 | aria-modal="true" 173 | tabindex="-1" 174 | style="pointer-events: auto" 175 | {@rest} 176 | > 177 | <%= render_slot(@inner_block) %> 178 | 179 | """ 180 | end 181 | 182 | attr(:as, :string, default: "h2") 183 | attr(:dialog, Dialog, required: true) 184 | attr(:rest, :global) 185 | slot(:inner_block, required: true) 186 | 187 | def title(assigns) do 188 | assigns = assign(assigns, id: Swish.EL.suffix_id(assigns.dialog, "title")) 189 | 190 | ~H""" 191 | <.dynamic_tag id={@id} name={@as} {@rest}> 192 | <%= render_slot(@inner_block) %> 193 | 194 | """ 195 | end 196 | 197 | attr(:as, :string, default: "p") 198 | attr(:dialog, Dialog, required: true) 199 | attr(:rest, :global) 200 | slot(:inner_block, required: true) 201 | 202 | def description(assigns) do 203 | assigns = assign(assigns, id: Swish.EL.suffix_id(assigns.dialog, "description")) 204 | 205 | ~H""" 206 | <.dynamic_tag id={@id} name={@as} {@rest}> 207 | <%= render_slot(@inner_block) %> 208 | 209 | """ 210 | end 211 | 212 | attr(:dialog, Dialog, required: true) 213 | attr(:target, :string, default: "body") 214 | attr(:update, :string, values: ~w(prepend append origin), default: "origin") 215 | 216 | slot(:inner_block, required: true) 217 | 218 | def portal(assigns) do 219 | ~H""" 220 | 231 | """ 232 | end 233 | 234 | defp show(%Dialog{js_show: fun} = dialog, js \\ %JS{}), do: fun.(js, dialog) 235 | defp hide(%Dialog{js_hide: fun} = dialog, js \\ %JS{}), do: fun.(js, dialog) 236 | 237 | defp open_to_state(%Dialog{open: open}) do 238 | case open do 239 | true -> "open" 240 | false -> "closed" 241 | _ -> raise "Expected boolean but received: #{inspect(open)}" 242 | end 243 | end 244 | end 245 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU AFFERO GENERAL PUBLIC LICENSE 2 | Version 3, 19 November 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU Affero General Public License is a free, copyleft license for 11 | software and other kinds of works, specifically designed to ensure 12 | cooperation with the community in the case of network server software. 13 | 14 | The licenses for most software and other practical works are designed 15 | to take away your freedom to share and change the works. By contrast, 16 | our General Public Licenses are intended to guarantee your freedom to 17 | share and change all versions of a program--to make sure it remains free 18 | software for all its users. 19 | 20 | When we speak of free software, we are referring to freedom, not 21 | price. Our General Public Licenses are designed to make sure that you 22 | have the freedom to distribute copies of free software (and charge for 23 | them if you wish), that you receive source code or can get it if you 24 | want it, that you can change the software or use pieces of it in new 25 | free programs, and that you know you can do these things. 26 | 27 | Developers that use our General Public Licenses protect your rights 28 | with two steps: (1) assert copyright on the software, and (2) offer 29 | you this License which gives you legal permission to copy, distribute 30 | and/or modify the software. 31 | 32 | A secondary benefit of defending all users' freedom is that 33 | improvements made in alternate versions of the program, if they 34 | receive widespread use, become available for other developers to 35 | incorporate. Many developers of free software are heartened and 36 | encouraged by the resulting cooperation. However, in the case of 37 | software used on network servers, this result may fail to come about. 38 | The GNU General Public License permits making a modified version and 39 | letting the public access it on a server without ever releasing its 40 | source code to the public. 41 | 42 | The GNU Affero General Public License is designed specifically to 43 | ensure that, in such cases, the modified source code becomes available 44 | to the community. It requires the operator of a network server to 45 | provide the source code of the modified version running there to the 46 | users of that server. Therefore, public use of a modified version, on 47 | a publicly accessible server, gives the public access to the source 48 | code of the modified version. 49 | 50 | An older license, called the Affero General Public License and 51 | published by Affero, was designed to accomplish similar goals. This is 52 | a different license, not a version of the Affero GPL, but Affero has 53 | released a new version of the Affero GPL which permits relicensing under 54 | this license. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | TERMS AND CONDITIONS 60 | 61 | 0. Definitions. 62 | 63 | "This License" refers to version 3 of the GNU Affero General Public License. 64 | 65 | "Copyright" also means copyright-like laws that apply to other kinds of 66 | works, such as semiconductor masks. 67 | 68 | "The Program" refers to any copyrightable work licensed under this 69 | License. Each licensee is addressed as "you". "Licensees" and 70 | "recipients" may be individuals or organizations. 71 | 72 | To "modify" a work means to copy from or adapt all or part of the work 73 | in a fashion requiring copyright permission, other than the making of an 74 | exact copy. The resulting work is called a "modified version" of the 75 | earlier work or a work "based on" the earlier work. 76 | 77 | A "covered work" means either the unmodified Program or a work based 78 | on the Program. 79 | 80 | To "propagate" a work means to do anything with it that, without 81 | permission, would make you directly or secondarily liable for 82 | infringement under applicable copyright law, except executing it on a 83 | computer or modifying a private copy. Propagation includes copying, 84 | distribution (with or without modification), making available to the 85 | public, and in some countries other activities as well. 86 | 87 | To "convey" a work means any kind of propagation that enables other 88 | parties to make or receive copies. Mere interaction with a user through 89 | a computer network, with no transfer of a copy, is not conveying. 90 | 91 | An interactive user interface displays "Appropriate Legal Notices" 92 | to the extent that it includes a convenient and prominently visible 93 | feature that (1) displays an appropriate copyright notice, and (2) 94 | tells the user that there is no warranty for the work (except to the 95 | extent that warranties are provided), that licensees may convey the 96 | work under this License, and how to view a copy of this License. If 97 | the interface presents a list of user commands or options, such as a 98 | menu, a prominent item in the list meets this criterion. 99 | 100 | 1. Source Code. 101 | 102 | The "source code" for a work means the preferred form of the work 103 | for making modifications to it. "Object code" means any non-source 104 | form of a work. 105 | 106 | A "Standard Interface" means an interface that either is an official 107 | standard defined by a recognized standards body, or, in the case of 108 | interfaces specified for a particular programming language, one that 109 | is widely used among developers working in that language. 110 | 111 | The "System Libraries" of an executable work include anything, other 112 | than the work as a whole, that (a) is included in the normal form of 113 | packaging a Major Component, but which is not part of that Major 114 | Component, and (b) serves only to enable use of the work with that 115 | Major Component, or to implement a Standard Interface for which an 116 | implementation is available to the public in source code form. A 117 | "Major Component", in this context, means a major essential component 118 | (kernel, window system, and so on) of the specific operating system 119 | (if any) on which the executable work runs, or a compiler used to 120 | produce the work, or an object code interpreter used to run it. 121 | 122 | The "Corresponding Source" for a work in object code form means all 123 | the source code needed to generate, install, and (for an executable 124 | work) run the object code and to modify the work, including scripts to 125 | control those activities. However, it does not include the work's 126 | System Libraries, or general-purpose tools or generally available free 127 | programs which are used unmodified in performing those activities but 128 | which are not part of the work. For example, Corresponding Source 129 | includes interface definition files associated with source files for 130 | the work, and the source code for shared libraries and dynamically 131 | linked subprograms that the work is specifically designed to require, 132 | such as by intimate data communication or control flow between those 133 | subprograms and other parts of the work. 134 | 135 | The Corresponding Source need not include anything that users 136 | can regenerate automatically from other parts of the Corresponding 137 | Source. 138 | 139 | The Corresponding Source for a work in source code form is that 140 | same work. 141 | 142 | 2. Basic Permissions. 143 | 144 | All rights granted under this License are granted for the term of 145 | copyright on the Program, and are irrevocable provided the stated 146 | conditions are met. This License explicitly affirms your unlimited 147 | permission to run the unmodified Program. The output from running a 148 | covered work is covered by this License only if the output, given its 149 | content, constitutes a covered work. This License acknowledges your 150 | rights of fair use or other equivalent, as provided by copyright law. 151 | 152 | You may make, run and propagate covered works that you do not 153 | convey, without conditions so long as your license otherwise remains 154 | in force. You may convey covered works to others for the sole purpose 155 | of having them make modifications exclusively for you, or provide you 156 | with facilities for running those works, provided that you comply with 157 | the terms of this License in conveying all material for which you do 158 | not control copyright. Those thus making or running the covered works 159 | for you must do so exclusively on your behalf, under your direction 160 | and control, on terms that prohibit them from making any copies of 161 | your copyrighted material outside their relationship with you. 162 | 163 | Conveying under any other circumstances is permitted solely under 164 | the conditions stated below. Sublicensing is not allowed; section 10 165 | makes it unnecessary. 166 | 167 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 168 | 169 | No covered work shall be deemed part of an effective technological 170 | measure under any applicable law fulfilling obligations under article 171 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 172 | similar laws prohibiting or restricting circumvention of such 173 | measures. 174 | 175 | When you convey a covered work, you waive any legal power to forbid 176 | circumvention of technological measures to the extent such circumvention 177 | is effected by exercising rights under this License with respect to 178 | the covered work, and you disclaim any intention to limit operation or 179 | modification of the work as a means of enforcing, against the work's 180 | users, your or third parties' legal rights to forbid circumvention of 181 | technological measures. 182 | 183 | 4. Conveying Verbatim Copies. 184 | 185 | You may convey verbatim copies of the Program's source code as you 186 | receive it, in any medium, provided that you conspicuously and 187 | appropriately publish on each copy an appropriate copyright notice; 188 | keep intact all notices stating that this License and any 189 | non-permissive terms added in accord with section 7 apply to the code; 190 | keep intact all notices of the absence of any warranty; and give all 191 | recipients a copy of this License along with the Program. 192 | 193 | You may charge any price or no price for each copy that you convey, 194 | and you may offer support or warranty protection for a fee. 195 | 196 | 5. Conveying Modified Source Versions. 197 | 198 | You may convey a work based on the Program, or the modifications to 199 | produce it from the Program, in the form of source code under the 200 | terms of section 4, provided that you also meet all of these conditions: 201 | 202 | a) The work must carry prominent notices stating that you modified 203 | it, and giving a relevant date. 204 | 205 | b) The work must carry prominent notices stating that it is 206 | released under this License and any conditions added under section 207 | 7. This requirement modifies the requirement in section 4 to 208 | "keep intact all notices". 209 | 210 | c) You must license the entire work, as a whole, under this 211 | License to anyone who comes into possession of a copy. This 212 | License will therefore apply, along with any applicable section 7 213 | additional terms, to the whole of the work, and all its parts, 214 | regardless of how they are packaged. This License gives no 215 | permission to license the work in any other way, but it does not 216 | invalidate such permission if you have separately received it. 217 | 218 | d) If the work has interactive user interfaces, each must display 219 | Appropriate Legal Notices; however, if the Program has interactive 220 | interfaces that do not display Appropriate Legal Notices, your 221 | work need not make them do so. 222 | 223 | A compilation of a covered work with other separate and independent 224 | works, which are not by their nature extensions of the covered work, 225 | and which are not combined with it such as to form a larger program, 226 | in or on a volume of a storage or distribution medium, is called an 227 | "aggregate" if the compilation and its resulting copyright are not 228 | used to limit the access or legal rights of the compilation's users 229 | beyond what the individual works permit. Inclusion of a covered work 230 | in an aggregate does not cause this License to apply to the other 231 | parts of the aggregate. 232 | 233 | 6. Conveying Non-Source Forms. 234 | 235 | You may convey a covered work in object code form under the terms 236 | of sections 4 and 5, provided that you also convey the 237 | machine-readable Corresponding Source under the terms of this License, 238 | in one of these ways: 239 | 240 | a) Convey the object code in, or embodied in, a physical product 241 | (including a physical distribution medium), accompanied by the 242 | Corresponding Source fixed on a durable physical medium 243 | customarily used for software interchange. 244 | 245 | b) Convey the object code in, or embodied in, a physical product 246 | (including a physical distribution medium), accompanied by a 247 | written offer, valid for at least three years and valid for as 248 | long as you offer spare parts or customer support for that product 249 | model, to give anyone who possesses the object code either (1) a 250 | copy of the Corresponding Source for all the software in the 251 | product that is covered by this License, on a durable physical 252 | medium customarily used for software interchange, for a price no 253 | more than your reasonable cost of physically performing this 254 | conveying of source, or (2) access to copy the 255 | Corresponding Source from a network server at no charge. 256 | 257 | c) Convey individual copies of the object code with a copy of the 258 | written offer to provide the Corresponding Source. This 259 | alternative is allowed only occasionally and noncommercially, and 260 | only if you received the object code with such an offer, in accord 261 | with subsection 6b. 262 | 263 | d) Convey the object code by offering access from a designated 264 | place (gratis or for a charge), and offer equivalent access to the 265 | Corresponding Source in the same way through the same place at no 266 | further charge. You need not require recipients to copy the 267 | Corresponding Source along with the object code. If the place to 268 | copy the object code is a network server, the Corresponding Source 269 | may be on a different server (operated by you or a third party) 270 | that supports equivalent copying facilities, provided you maintain 271 | clear directions next to the object code saying where to find the 272 | Corresponding Source. Regardless of what server hosts the 273 | Corresponding Source, you remain obligated to ensure that it is 274 | available for as long as needed to satisfy these requirements. 275 | 276 | e) Convey the object code using peer-to-peer transmission, provided 277 | you inform other peers where the object code and Corresponding 278 | Source of the work are being offered to the general public at no 279 | charge under subsection 6d. 280 | 281 | A separable portion of the object code, whose source code is excluded 282 | from the Corresponding Source as a System Library, need not be 283 | included in conveying the object code work. 284 | 285 | A "User Product" is either (1) a "consumer product", which means any 286 | tangible personal property which is normally used for personal, family, 287 | or household purposes, or (2) anything designed or sold for incorporation 288 | into a dwelling. In determining whether a product is a consumer product, 289 | doubtful cases shall be resolved in favor of coverage. For a particular 290 | product received by a particular user, "normally used" refers to a 291 | typical or common use of that class of product, regardless of the status 292 | of the particular user or of the way in which the particular user 293 | actually uses, or expects or is expected to use, the product. A product 294 | is a consumer product regardless of whether the product has substantial 295 | commercial, industrial or non-consumer uses, unless such uses represent 296 | the only significant mode of use of the product. 297 | 298 | "Installation Information" for a User Product means any methods, 299 | procedures, authorization keys, or other information required to install 300 | and execute modified versions of a covered work in that User Product from 301 | a modified version of its Corresponding Source. The information must 302 | suffice to ensure that the continued functioning of the modified object 303 | code is in no case prevented or interfered with solely because 304 | modification has been made. 305 | 306 | If you convey an object code work under this section in, or with, or 307 | specifically for use in, a User Product, and the conveying occurs as 308 | part of a transaction in which the right of possession and use of the 309 | User Product is transferred to the recipient in perpetuity or for a 310 | fixed term (regardless of how the transaction is characterized), the 311 | Corresponding Source conveyed under this section must be accompanied 312 | by the Installation Information. But this requirement does not apply 313 | if neither you nor any third party retains the ability to install 314 | modified object code on the User Product (for example, the work has 315 | been installed in ROM). 316 | 317 | The requirement to provide Installation Information does not include a 318 | requirement to continue to provide support service, warranty, or updates 319 | for a work that has been modified or installed by the recipient, or for 320 | the User Product in which it has been modified or installed. Access to a 321 | network may be denied when the modification itself materially and 322 | adversely affects the operation of the network or violates the rules and 323 | protocols for communication across the network. 324 | 325 | Corresponding Source conveyed, and Installation Information provided, 326 | in accord with this section must be in a format that is publicly 327 | documented (and with an implementation available to the public in 328 | source code form), and must require no special password or key for 329 | unpacking, reading or copying. 330 | 331 | 7. Additional Terms. 332 | 333 | "Additional permissions" are terms that supplement the terms of this 334 | License by making exceptions from one or more of its conditions. 335 | Additional permissions that are applicable to the entire Program shall 336 | be treated as though they were included in this License, to the extent 337 | that they are valid under applicable law. If additional permissions 338 | apply only to part of the Program, that part may be used separately 339 | under those permissions, but the entire Program remains governed by 340 | this License without regard to the additional permissions. 341 | 342 | When you convey a copy of a covered work, you may at your option 343 | remove any additional permissions from that copy, or from any part of 344 | it. (Additional permissions may be written to require their own 345 | removal in certain cases when you modify the work.) You may place 346 | additional permissions on material, added by you to a covered work, 347 | for which you have or can give appropriate copyright permission. 348 | 349 | Notwithstanding any other provision of this License, for material you 350 | add to a covered work, you may (if authorized by the copyright holders of 351 | that material) supplement the terms of this License with terms: 352 | 353 | a) Disclaiming warranty or limiting liability differently from the 354 | terms of sections 15 and 16 of this License; or 355 | 356 | b) Requiring preservation of specified reasonable legal notices or 357 | author attributions in that material or in the Appropriate Legal 358 | Notices displayed by works containing it; or 359 | 360 | c) Prohibiting misrepresentation of the origin of that material, or 361 | requiring that modified versions of such material be marked in 362 | reasonable ways as different from the original version; or 363 | 364 | d) Limiting the use for publicity purposes of names of licensors or 365 | authors of the material; or 366 | 367 | e) Declining to grant rights under trademark law for use of some 368 | trade names, trademarks, or service marks; or 369 | 370 | f) Requiring indemnification of licensors and authors of that 371 | material by anyone who conveys the material (or modified versions of 372 | it) with contractual assumptions of liability to the recipient, for 373 | any liability that these contractual assumptions directly impose on 374 | those licensors and authors. 375 | 376 | All other non-permissive additional terms are considered "further 377 | restrictions" within the meaning of section 10. If the Program as you 378 | received it, or any part of it, contains a notice stating that it is 379 | governed by this License along with a term that is a further 380 | restriction, you may remove that term. If a license document contains 381 | a further restriction but permits relicensing or conveying under this 382 | License, you may add to a covered work material governed by the terms 383 | of that license document, provided that the further restriction does 384 | not survive such relicensing or conveying. 385 | 386 | If you add terms to a covered work in accord with this section, you 387 | must place, in the relevant source files, a statement of the 388 | additional terms that apply to those files, or a notice indicating 389 | where to find the applicable terms. 390 | 391 | Additional terms, permissive or non-permissive, may be stated in the 392 | form of a separately written license, or stated as exceptions; 393 | the above requirements apply either way. 394 | 395 | 8. Termination. 396 | 397 | You may not propagate or modify a covered work except as expressly 398 | provided under this License. Any attempt otherwise to propagate or 399 | modify it is void, and will automatically terminate your rights under 400 | this License (including any patent licenses granted under the third 401 | paragraph of section 11). 402 | 403 | However, if you cease all violation of this License, then your 404 | license from a particular copyright holder is reinstated (a) 405 | provisionally, unless and until the copyright holder explicitly and 406 | finally terminates your license, and (b) permanently, if the copyright 407 | holder fails to notify you of the violation by some reasonable means 408 | prior to 60 days after the cessation. 409 | 410 | Moreover, your license from a particular copyright holder is 411 | reinstated permanently if the copyright holder notifies you of the 412 | violation by some reasonable means, this is the first time you have 413 | received notice of violation of this License (for any work) from that 414 | copyright holder, and you cure the violation prior to 30 days after 415 | your receipt of the notice. 416 | 417 | Termination of your rights under this section does not terminate the 418 | licenses of parties who have received copies or rights from you under 419 | this License. If your rights have been terminated and not permanently 420 | reinstated, you do not qualify to receive new licenses for the same 421 | material under section 10. 422 | 423 | 9. Acceptance Not Required for Having Copies. 424 | 425 | You are not required to accept this License in order to receive or 426 | run a copy of the Program. Ancillary propagation of a covered work 427 | occurring solely as a consequence of using peer-to-peer transmission 428 | to receive a copy likewise does not require acceptance. However, 429 | nothing other than this License grants you permission to propagate or 430 | modify any covered work. These actions infringe copyright if you do 431 | not accept this License. Therefore, by modifying or propagating a 432 | covered work, you indicate your acceptance of this License to do so. 433 | 434 | 10. Automatic Licensing of Downstream Recipients. 435 | 436 | Each time you convey a covered work, the recipient automatically 437 | receives a license from the original licensors, to run, modify and 438 | propagate that work, subject to this License. You are not responsible 439 | for enforcing compliance by third parties with this License. 440 | 441 | An "entity transaction" is a transaction transferring control of an 442 | organization, or substantially all assets of one, or subdividing an 443 | organization, or merging organizations. If propagation of a covered 444 | work results from an entity transaction, each party to that 445 | transaction who receives a copy of the work also receives whatever 446 | licenses to the work the party's predecessor in interest had or could 447 | give under the previous paragraph, plus a right to possession of the 448 | Corresponding Source of the work from the predecessor in interest, if 449 | the predecessor has it or can get it with reasonable efforts. 450 | 451 | You may not impose any further restrictions on the exercise of the 452 | rights granted or affirmed under this License. For example, you may 453 | not impose a license fee, royalty, or other charge for exercise of 454 | rights granted under this License, and you may not initiate litigation 455 | (including a cross-claim or counterclaim in a lawsuit) alleging that 456 | any patent claim is infringed by making, using, selling, offering for 457 | sale, or importing the Program or any portion of it. 458 | 459 | 11. Patents. 460 | 461 | A "contributor" is a copyright holder who authorizes use under this 462 | License of the Program or a work on which the Program is based. The 463 | work thus licensed is called the contributor's "contributor version". 464 | 465 | A contributor's "essential patent claims" are all patent claims 466 | owned or controlled by the contributor, whether already acquired or 467 | hereafter acquired, that would be infringed by some manner, permitted 468 | by this License, of making, using, or selling its contributor version, 469 | but do not include claims that would be infringed only as a 470 | consequence of further modification of the contributor version. For 471 | purposes of this definition, "control" includes the right to grant 472 | patent sublicenses in a manner consistent with the requirements of 473 | this License. 474 | 475 | Each contributor grants you a non-exclusive, worldwide, royalty-free 476 | patent license under the contributor's essential patent claims, to 477 | make, use, sell, offer for sale, import and otherwise run, modify and 478 | propagate the contents of its contributor version. 479 | 480 | In the following three paragraphs, a "patent license" is any express 481 | agreement or commitment, however denominated, not to enforce a patent 482 | (such as an express permission to practice a patent or covenant not to 483 | sue for patent infringement). To "grant" such a patent license to a 484 | party means to make such an agreement or commitment not to enforce a 485 | patent against the party. 486 | 487 | If you convey a covered work, knowingly relying on a patent license, 488 | and the Corresponding Source of the work is not available for anyone 489 | to copy, free of charge and under the terms of this License, through a 490 | publicly available network server or other readily accessible means, 491 | then you must either (1) cause the Corresponding Source to be so 492 | available, or (2) arrange to deprive yourself of the benefit of the 493 | patent license for this particular work, or (3) arrange, in a manner 494 | consistent with the requirements of this License, to extend the patent 495 | license to downstream recipients. "Knowingly relying" means you have 496 | actual knowledge that, but for the patent license, your conveying the 497 | covered work in a country, or your recipient's use of the covered work 498 | in a country, would infringe one or more identifiable patents in that 499 | country that you have reason to believe are valid. 500 | 501 | If, pursuant to or in connection with a single transaction or 502 | arrangement, you convey, or propagate by procuring conveyance of, a 503 | covered work, and grant a patent license to some of the parties 504 | receiving the covered work authorizing them to use, propagate, modify 505 | or convey a specific copy of the covered work, then the patent license 506 | you grant is automatically extended to all recipients of the covered 507 | work and works based on it. 508 | 509 | A patent license is "discriminatory" if it does not include within 510 | the scope of its coverage, prohibits the exercise of, or is 511 | conditioned on the non-exercise of one or more of the rights that are 512 | specifically granted under this License. You may not convey a covered 513 | work if you are a party to an arrangement with a third party that is 514 | in the business of distributing software, under which you make payment 515 | to the third party based on the extent of your activity of conveying 516 | the work, and under which the third party grants, to any of the 517 | parties who would receive the covered work from you, a discriminatory 518 | patent license (a) in connection with copies of the covered work 519 | conveyed by you (or copies made from those copies), or (b) primarily 520 | for and in connection with specific products or compilations that 521 | contain the covered work, unless you entered into that arrangement, 522 | or that patent license was granted, prior to 28 March 2007. 523 | 524 | Nothing in this License shall be construed as excluding or limiting 525 | any implied license or other defenses to infringement that may 526 | otherwise be available to you under applicable patent law. 527 | 528 | 12. No Surrender of Others' Freedom. 529 | 530 | If conditions are imposed on you (whether by court order, agreement or 531 | otherwise) that contradict the conditions of this License, they do not 532 | excuse you from the conditions of this License. If you cannot convey a 533 | covered work so as to satisfy simultaneously your obligations under this 534 | License and any other pertinent obligations, then as a consequence you may 535 | not convey it at all. For example, if you agree to terms that obligate you 536 | to collect a royalty for further conveying from those to whom you convey 537 | the Program, the only way you could satisfy both those terms and this 538 | License would be to refrain entirely from conveying the Program. 539 | 540 | 13. Remote Network Interaction; Use with the GNU General Public License. 541 | 542 | Notwithstanding any other provision of this License, if you modify the 543 | Program, your modified version must prominently offer all users 544 | interacting with it remotely through a computer network (if your version 545 | supports such interaction) an opportunity to receive the Corresponding 546 | Source of your version by providing access to the Corresponding Source 547 | from a network server at no charge, through some standard or customary 548 | means of facilitating copying of software. This Corresponding Source 549 | shall include the Corresponding Source for any work covered by version 3 550 | of the GNU General Public License that is incorporated pursuant to the 551 | following paragraph. 552 | 553 | Notwithstanding any other provision of this License, you have 554 | permission to link or combine any covered work with a work licensed 555 | under version 3 of the GNU General Public License into a single 556 | combined work, and to convey the resulting work. The terms of this 557 | License will continue to apply to the part which is the covered work, 558 | but the work with which it is combined will remain governed by version 559 | 3 of the GNU General Public License. 560 | 561 | 14. Revised Versions of this License. 562 | 563 | The Free Software Foundation may publish revised and/or new versions of 564 | the GNU Affero General Public License from time to time. Such new versions 565 | will be similar in spirit to the present version, but may differ in detail to 566 | address new problems or concerns. 567 | 568 | Each version is given a distinguishing version number. If the 569 | Program specifies that a certain numbered version of the GNU Affero General 570 | Public License "or any later version" applies to it, you have the 571 | option of following the terms and conditions either of that numbered 572 | version or of any later version published by the Free Software 573 | Foundation. If the Program does not specify a version number of the 574 | GNU Affero General Public License, you may choose any version ever published 575 | by the Free Software Foundation. 576 | 577 | If the Program specifies that a proxy can decide which future 578 | versions of the GNU Affero General Public License can be used, that proxy's 579 | public statement of acceptance of a version permanently authorizes you 580 | to choose that version for the Program. 581 | 582 | Later license versions may give you additional or different 583 | permissions. However, no additional obligations are imposed on any 584 | author or copyright holder as a result of your choosing to follow a 585 | later version. 586 | 587 | 15. Disclaimer of Warranty. 588 | 589 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 590 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 591 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 592 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 593 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 594 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 595 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 596 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 597 | 598 | 16. Limitation of Liability. 599 | 600 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 601 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 602 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 603 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 604 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 605 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 606 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 607 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 608 | SUCH DAMAGES. 609 | 610 | 17. Interpretation of Sections 15 and 16. 611 | 612 | If the disclaimer of warranty and limitation of liability provided 613 | above cannot be given local legal effect according to their terms, 614 | reviewing courts shall apply local law that most closely approximates 615 | an absolute waiver of all civil liability in connection with the 616 | Program, unless a warranty or assumption of liability accompanies a 617 | copy of the Program in return for a fee. 618 | 619 | END OF TERMS AND CONDITIONS 620 | 621 | How to Apply These Terms to Your New Programs 622 | 623 | If you develop a new program, and you want it to be of the greatest 624 | possible use to the public, the best way to achieve this is to make it 625 | free software which everyone can redistribute and change under these terms. 626 | 627 | To do so, attach the following notices to the program. It is safest 628 | to attach them to the start of each source file to most effectively 629 | state the exclusion of warranty; and each file should have at least 630 | the "copyright" line and a pointer to where the full notice is found. 631 | 632 | 633 | Copyright (C) 634 | 635 | This program is free software: you can redistribute it and/or modify 636 | it under the terms of the GNU Affero General Public License as published 637 | by the Free Software Foundation, either version 3 of the License, or 638 | (at your option) any later version. 639 | 640 | This program is distributed in the hope that it will be useful, 641 | but WITHOUT ANY WARRANTY; without even the implied warranty of 642 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 643 | GNU Affero General Public License for more details. 644 | 645 | You should have received a copy of the GNU Affero General Public License 646 | along with this program. If not, see . 647 | 648 | Also add information on how to contact you by electronic and paper mail. 649 | 650 | If your software can interact with users remotely through a computer 651 | network, you should also make sure that it provides a way for users to 652 | get its source. For example, if your program is a web application, its 653 | interface could display a "Source" link that leads users to an archive 654 | of the code. There are many ways you could offer source, and different 655 | solutions will be better for different programs; see section 13 for the 656 | specific requirements. 657 | 658 | You should also get your employer (if you work as a programmer) or school, 659 | if any, to sign a "copyright disclaimer" for the program, if necessary. 660 | For more information on this, and how to apply and follow the GNU AGPL, see 661 | . 662 | --------------------------------------------------------------------------------