keystone_ui-preferences 0.7.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +54 -27
  3. data/app/controllers/concerns/keystone_ui/preferences/component_preferences.rb +2 -2
  4. data/app/javascript/keystone_ui/preferences/appearance_editor_controller.js +235 -0
  5. data/app/models/keystone_ui/preferences/appearance_choice.rb +66 -1
  6. data/app/models/keystone_ui/preferences/checked_theme.rb +109 -0
  7. data/app/models/keystone_ui/preferences/chosen_colours.rb +7 -2
  8. data/app/models/keystone_ui/preferences/pick_account_appearance.rb +12 -2
  9. data/app/models/keystone_ui/preferences/pick_appearance.rb +13 -1
  10. data/app/models/keystone_ui/preferences/sent_theme.rb +49 -0
  11. data/app/models/keystone_ui/preferences/theme_css.rb +89 -0
  12. data/app/models/keystone_ui/preferences/theme_reader.rb +34 -0
  13. data/app/models/keystone_ui/preferences/theme_roles.rb +89 -0
  14. data/app/views/keystone_ui/preferences/settings/_account_appearance.html.erb +15 -3
  15. data/app/views/keystone_ui/preferences/settings/_appearance.html.erb +30 -18
  16. data/app/views/keystone_ui/preferences/settings/_colour_choices.html.erb +40 -8
  17. data/app/views/keystone_ui/preferences/settings/_editor_layout.html.erb +29 -0
  18. data/app/views/keystone_ui/preferences/settings/_theme_preview.html.erb +34 -0
  19. data/app/views/keystone_ui/preferences/settings/_theme_settings.html.erb +52 -0
  20. data/lib/generators/keystone_ui/preferences/install/install_generator.rb +4 -4
  21. data/lib/generators/keystone_ui/preferences/update/update_generator.rb +4 -4
  22. data/lib/keystone_ui/preferences/colors_check.rb +3 -2
  23. data/lib/keystone_ui/preferences/configuration.rb +2 -1
  24. data/lib/keystone_ui/preferences/version.rb +1 -1
  25. metadata +28 -7
  26. data/app/javascript/keystone_ui/preferences/theme_settings_controller.js +0 -59
  27. data/app/models/keystone_ui/preferences/palette_css.rb +0 -32
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bbf5cec0b85185ca3abee2d52c65c7e80f26044c9a0c7fb9a19df0fdba9464c6
4
- data.tar.gz: a1885de65a350f4f7025fa2bdb1eb160a11d1f9402a4b38615672a4621a4d2bc
3
+ metadata.gz: e09ee48853d6dd4eae14eb48ac7686dc6c4329e329cecbd199f7e53e13aa8001
4
+ data.tar.gz: 95ff23cb290be1c1ec798f26dff2c88c7ffa321424f811693697a6fed46d732e
5
5
  SHA512:
6
- metadata.gz: 834b8955f9a2048c833372321b52c13829376dc0d906e4c66d30bd4ef5d9b356f894057f6b1005c166d5b72e9fe33f1df7556f52bd6a9182e59613885c24771e
7
- data.tar.gz: 30eb7dbafec075ee43fd6d1cc80a1af79fa6b9ef8c3eb1f68ef250f12f7a1fb042f44b9b1dccdd86580a52ac3de5c5ed15e4495ad0c8476887ba2dfac1bf53b1
6
+ metadata.gz: fe83084aafb891f389bbd94524e7c257c69d375f8009835fd6492e8e855c41d50f2625a09467f48de25f70adb47d7a9505c37fd6997d223255ca8a0a467c8cf1
7
+ data.tar.gz: 15825f59455347b377c02e1a82092e02789141969664410da902db37386547fed82c47e3c9da22656e754bf45562433382ce3103b1fb4f01a2430b63f08b42a9
data/README.md CHANGED
@@ -6,7 +6,7 @@ A page gives a `ui_data_table` a `key:`. This gem saves each signed-in person's
6
6
 
7
7
  ## Installation
8
8
 
9
- Add the gem and run its install generator, which copies a migration for its table and the template picker script the appearance section uses:
9
+ Add the gem and run its install generator, which copies a migration for its table and the appearance editor script the Appearance sections use:
10
10
 
11
11
  ```ruby
12
12
  gem "keystone_ui-preferences"
@@ -18,20 +18,22 @@ bin/rails generate keystone_ui:preferences:install
18
18
  bin/rails db:migrate
19
19
  ```
20
20
 
21
- The script lands at `app/javascript/controllers/keystone_ui/preferences/theme_settings_controller.js`. Register it in `app/javascript/controllers/index.js`:
21
+ The script lands at `app/javascript/controllers/keystone_ui/preferences/appearance_editor_controller.js`. Register it in `app/javascript/controllers/index.js`:
22
22
 
23
23
  ```js
24
- import ThemeSettingsController from "./keystone_ui/preferences/theme_settings_controller"
25
- application.register("keystone-ui--preferences--theme-settings", ThemeSettingsController)
24
+ import AppearanceEditorController from "./keystone_ui/preferences/appearance_editor_controller"
25
+ application.register("keystone-ui--preferences--appearance-editor", AppearanceEditorController)
26
26
  ```
27
27
 
28
- After updating the gem, run its update generator to copy any migrations added since it was installed, and the template picker script when the app does not have it yet:
28
+ After updating the gem, run its update generator to copy any migrations added since it was installed, and the appearance editor script when the app does not have it yet:
29
29
 
30
30
  ```bash
31
31
  bin/rails generate keystone_ui:preferences:update
32
32
  bin/rails db:migrate
33
33
  ```
34
34
 
35
+ An app that installed an earlier version has a template picker script at `app/javascript/controllers/keystone_ui/preferences/theme_settings_controller.js` and a theme editor script at `app/javascript/controllers/keystone_ui/preferences/theme_editor_controller.js`. The appearance editor script replaces both. Register the appearance editor script as shown above. Then remove both old scripts and the two lines in `app/javascript/controllers/index.js` that register them as `keystone-ui--preferences--theme-settings` and `keystone-ui--preferences--theme-editor`. The update generator copies the new script and leaves both old scripts in place, so removing them is the app's own step.
36
+
35
37
  Mount the engine in `config/routes.rb`. A table's Columns menu saves to it:
36
38
 
37
39
  ```ruby
@@ -65,6 +67,7 @@ KeystoneUi::Preferences.configure do |config|
65
67
  config.app_look_label = "Classic" # the label for the app's own look in the appearance section
66
68
  config.account_colors = true # whether an account may choose its colours, and its members their own
67
69
  config.account_looks = true # whether an account may choose its look
70
+ config.theme_fonts = [] # fonts the app serves itself that a pasted theme may name
68
71
  end
69
72
  ```
70
73
 
@@ -159,11 +162,17 @@ Add the palette style tag to your layout's `<head>`:
159
162
 
160
163
  It writes the same CSS variables keystone_ui-colors writes: `--color-accent-50` to `--color-accent-950`, `--color-surface-50` to `--color-surface-950`, `--color-custom-background` and `--color-custom-text`. A layout that already calls it for keystone_ui-colors keeps working unchanged, and an app that loads both gems stops at boot.
161
164
 
162
- The colours come from the `colours` key, read the way a table's layout is read: the person's own row, or the account's row when the account does not let members choose. A saved value looks like `{ "accent": "#e11d48", "surface": "#f5e6c8", "text": "#3b2f1e" }` or `{ "template_name": "forest" }`. A named accent or surface, such as `emerald` or `stone`, uses that palette's shades from keystone_ui-looks, and a hex value has its shades generated. A custom hex surface is also the custom background. A saved accent or surface that is neither a name of lowercase letters, digits and underscores nor a six-digit hex, and a saved text colour that is not a six-digit hex, is drawn as the configured default for that colour instead.
165
+ The colours come from the `colours` key, read the way a table's layout is read: the person's own row, or the account's row when the account does not let members choose. A saved value looks like `{ "accent": "#e11d48", "surface": "#f5e6c8", "text": "#3b2f1e" }`, `{ "template_name": "forest" }`, `{ "preset_name": "harbor" }` or a pasted theme, described under Appearance. A named accent or surface, such as `emerald` or `stone`, uses that palette's shades from keystone_ui-looks, and a hex value has its shades generated. A custom hex surface is also the custom background. A saved accent or surface that is neither a name of lowercase letters, digits and underscores nor a six-digit hex, and a saved text colour that is not a six-digit hex, is drawn as the configured default for that colour instead.
163
166
 
164
167
  A saved `template_name` draws that template's accent, surface, background and text from keystone_ui-looks, whatever else the value holds. The template named `default` is built from the four defaults in the configuration. A person with nothing saved, and a visitor who is not signed in, see those four defaults.
165
168
 
166
- A saved name keystone_ui-looks no longer has still draws a page. A missing template draws the account's colours, or the four defaults when the account has none or its own template is the missing one. A missing accent or surface name draws the default accent or surface. Each of these writes one warning to the app's log naming the owner's type and id and the missing name, for example `keystone_ui-preferences: User 5 saved the template "retired", which keystone_ui-looks does not have`. A saved value that is not a name or a six-digit hex falls back with no warning. The saved row is left as it is until the owner saves again, and the appearance section shows no template selected for it.
169
+ A saved theme is written into the same style tag as a second rule, after the palette, setting the `--ks-*` variables of keystone_ui-styles that each theme role maps to. A role's light value sets each of its variables and its dark value sets each variable's `-dark` partner, so Dark mode, and System mode on a device that prefers dark, draw the theme's dark values. A role with no dark value keeps today's dark colour, and a role that maps to no variable, such as `sidebar-ring`, sets nothing. The accent, neutral and danger hover colours are derived from `primary`, `secondary` and `destructive` by mixing in 15% white. The rule's selector is `:root, html:root[data-look]`, so a theme's colours win over the colours a look sets. React components from keystone_ui-react use the same `ks-` classes, so they draw the same theme colours. The theme is checked again before it is written. A saved theme holding a value that fails the check, such as one saved before a rule was tightened, or one that is not a set of roles each holding light and dark values, is not written, and the page draws the account's colours and theme instead, or the app's defaults when the account has none or its own theme is the one that fails. Each such page writes one warning to the app's log naming the owner's type and id and the first setting that fails, for example `keystone_ui-preferences: User 5 saved a theme whose --radius setting fails the theme check`, or says the theme is not a set of roles, for example `keystone_ui-preferences: User 5 saved a theme that is not a set of roles, so it fails the theme check`. The written rule is kept in `Rails.cache` under the colours row's versioned cache key and the writer's version, so a saved change, or a new release of the writer, shows on the next page. No theme is written while `account_colors` is off.
170
+
171
+ A saved theme's shape and type are written into the same rule. `radius` sets `--ks-radius-control` and `--ks-radius-surface`, `spacing` sets `--ks-spacing`, `border-width` sets `--ks-border-width`, `letter-spacing` sets `--ks-letter-spacing`, `font-sans` sets `--ks-font-body`, `font-heading` sets `--ks-font-heading`, and `font-weight-normal`, `font-weight-medium`, `font-weight-strong` and `font-weight-heading` set the matching `--ks-font-weight-*` variable. `font-mono` sets both `--ks-font-mono` and Tailwind's `--default-mono-font-family`, since keystone_ui-styles draws code with the second, and a theme with no mono font sets neither. `font-serif` is saved but sets nothing. A theme that sets all six shadow settings writes one shadow, `<offset-x> <offset-y> <blur> <spread>` in the shadow colour mixed to the shadow opacity, to `--ks-shadow-surface`, `--ks-shadow-overlay` and `--ks-shadow-menu`, and a theme missing any of the six writes no shadow. Shape and type have no dark values. For a person who saved a look of their own, the shape and type go in a separate `:root` rule, so their look's corners, spacing, shadows, borders and fonts win over the theme's while the theme's colours still win over the look's. A look that comes only from the account or the app's default does not outrank the theme's shape and type. Whether the person saved a look is part of the cache key, so saving or removing one shows on the next page.
172
+
173
+ A saved `preset_name` writes that preset theme from keystone_ui-looks into the same rule a saved theme is written into, looked up on each page rather than copied into the row, so a preset changed in a later keystone_ui-looks release reaches everyone who picked it. The preset's values are checked as a saved theme's are before they are written. The written rule is kept in `Rails.cache` under the preset's name, the keystone_ui-looks version, the writer's version and whether the person saved a look of their own.
174
+
175
+ A saved name keystone_ui-looks no longer has still draws a page. A missing template draws the account's colours, or the four defaults when the account has none or its own template is the missing one. A missing accent or surface name draws the default accent or surface. A missing preset falls back the same way as a missing template, to the account's colours and theme, or to the four defaults when the account has none or its own preset is the missing one. Each of these writes one warning to the app's log naming the owner's type and id and the missing name, for example `keystone_ui-preferences: User 5 saved the template "retired", which keystone_ui-looks does not have`. A saved value that is not a name or a six-digit hex falls back with no warning. The saved row is left as it is until the owner saves again, and the appearance section shows no template selected for it.
167
176
 
168
177
  ## Appearance
169
178
 
@@ -175,11 +184,31 @@ SettingsHub.section :appearance, area: :user, title: "Appearance",
175
184
  runs: "KeystoneUi::Preferences::PickAppearance"
176
185
  ```
177
186
 
178
- The section looks and behaves as keystone_ui-colors' colour settings do. It offers Default, the five named templates from keystone_ui-looks and Custom, with an accent, a surface and a text colour picker under them. The person's own saved choice is selected, or Default when they have none, and the pickers show the colours drawn for them now. Picking a template sets the pickers to that template's colours at once, and changing a picker selects Custom, through the template picker script the install generator copies. Without the script the section still saves, and the form saves with a full page load, so it works in a Hotwire Native web view.
187
+ The section looks and behaves as keystone_ui-colors' colour settings do. It offers Default, the five named templates from keystone_ui-looks, the six preset themes from keystone_ui-looks and Custom, with an accent, a surface and a text colour picker under them. The person's own saved choice is selected, or Default when they have none, and the pickers show the colours drawn for them now. Picking a template sets the pickers to that template's colours at once, and changing a picker selects Custom, through the appearance editor script the install generator copies. Without the script the section still saves, and the form saves with a full page load, so it works in a Hotwire Native web view.
188
+
189
+ Saving a template keeps `{ "template_name": "forest" }` for that person under the `colours` key. Saving a preset theme keeps only its name, as `{ "preset_name": "harbor" }`. Saving Custom keeps `{ "accent": "#e11d48", "surface": "#f5e6c8", "text": "#3b2f1e" }`. Saving Default removes the person's `colours` row, so the account's colours, or the app's defaults, apply again. The next page the person opens is drawn in the saved colours.
190
+
191
+ A template or preset name that is not Default, one of the five templates or one of the six preset themes is refused with a message, and so is a Custom accent or surface that is neither a six-digit hex nor a palette name from keystone_ui-looks, and a text colour that is not a six-digit hex. Nothing is saved.
192
+
193
+ The Theme section also has a paste box for a theme in shadcn/ui's variable names, as tweakcn and shadcn's theme pages export it. Only declarations in a `:root` block and a `.dark` block are read, either at the top level or inside an `@layer` rule, and only the theme's settings are kept. Those are the 32 shadcn colour roles: `background`, `foreground`, `card`, `card-foreground`, `popover`, `popover-foreground`, `primary`, `primary-foreground`, `secondary`, `secondary-foreground`, `muted`, `muted-foreground`, `accent`, `accent-foreground`, `destructive`, `destructive-foreground`, `border`, `input`, `ring`, `chart-1` to `chart-5` and the eight `sidebar` roles. They are also shadcn's shape and type settings, `radius`, `spacing`, `letter-spacing`, `font-sans`, `font-serif`, `font-mono`, `shadow-color`, `shadow-opacity`, `shadow-blur`, `shadow-spread`, `shadow-offset-x` and `shadow-offset-y`. Last are the settings shadcn has no name for, `border-width`, `font-heading`, `font-weight-normal`, `font-weight-medium`, `font-weight-strong` and `font-weight-heading`. Every other declaration, selector and rule is ignored, including ready-made shadows such as `--shadow-sm`.
194
+
195
+ Each colour must be a hex colour or an `rgb()`, `hsl()` or `oklch()` colour written with plain numbers, such as `oklch(0.205 0 0)` or `oklch(1 0 0 / 10%)`. Saving keeps only the checked colours, as `{ "theme": { "primary": { "light": "oklch(0.205 0 0)", "dark": "oklch(0.922 0 0)" } } }` under the `colours` key, and the pasted text itself is never stored. A role with no value in the `.dark` block is kept with a light value alone.
179
196
 
180
- Saving a template keeps `{ "template_name": "forest" }` for that person under the `colours` key. Saving Custom keeps `{ "accent": "#e11d48", "surface": "#f5e6c8", "text": "#3b2f1e" }`. Saving Default removes the person's `colours` row, so the account's colours, or the app's defaults, apply again. The next page the person opens is drawn in the saved colours.
197
+ Shape and type settings are kept from the `:root` block only, as `{ "radius": { "light": "0.5rem" } }`, and each is checked by its kind. A radius, spacing, border width or shadow blur must be a number followed by `px`, `rem` or `em`, or zero. A shadow's spread and offsets, and a letter spacing, may also be negative, and a letter spacing may be `normal`. A shadow colour is checked as a colour, a shadow opacity must be a number from 0 to 1, and a font weight must be a whole hundred from 100 to 900. A font list must be comma-separated names made of letters, digits, spaces and hyphens, each optionally in single or double quotes. A font in the list is kept only when the app names it in `theme_fonts` or it is one of the system fonts the gem lists: `system-ui`, `ui-sans-serif`, `ui-serif`, `ui-monospace`, `ui-rounded`, `sans-serif`, `serif`, `monospace`, `cursive`, `-apple-system`, `BlinkMacSystemFont`, `Segoe UI`, `Roboto`, `Helvetica`, `Helvetica Neue`, `Arial`, `Georgia`, `Times New Roman`, `Menlo`, `Monaco`, `Consolas`, `Courier New` and `SFMono-Regular`. Any other font is dropped, so the browser uses the next font in the list and nothing is requested from another site. A kept name of more than one word is written in double quotes and a one-word name is written bare. The gem loads no font file, so an app that names a font in `theme_fonts` serves that font itself. The Theme section then says the current choice is the person's own theme and selects no template. The palette style tag then writes the theme onto every page, as described under Colours.
181
198
 
182
- A template that is not Default or one of the five is refused with a message, and so is a Custom accent or surface that is neither a six-digit hex nor a palette name from keystone_ui-looks, and a text colour that is not a six-digit hex. Nothing is saved.
199
+ Each refusal below saves nothing and says why. A paste over 20,000 characters is refused before any of it is read. A paste containing `url(` or `@import` anywhere is refused. A paste with no shadcn colour role in a `:root` or `.dark` block is refused. A colour that fails the check is refused with a message naming the role and whether it is the light or dark value. A shape or type value that fails its check is refused with a message naming the setting, and so is a font list left with no font the app offers. A paste is refused with the same message as other colours while the account sets the colours for everyone.
200
+
201
+ After Look and Mode, the section lists every theme setting as its own field, named by its shadcn variable, with no closed disclosure around them. The fields are grouped as tweakcn's editor groups them. Colors holds the colour roles in sets, each with its foreground beside it: Page (`background` and `foreground`), Primary, Secondary, Accent, Muted, Card, Popover, Destructive, Border, input and ring, Chart (`chart-1` to `chart-5`) and the eight Sidebar roles. Typography holds the sans, serif, mono and heading fonts, the four font weights and the letter spacing. Other holds the radius, the spacing, the border width and the six shadow settings. Each colour role has a light and a dark keystone_ui colour picker side by side, and the shadow colour has one, so a colour can be typed as hex, `rgb()`, `hsl()` or `oklch()`. Every other setting is a text field. Each font field suggests the fonts in `theme_fonts` and then the system fonts the gem offers, and still takes a typed list of several fonts. The fields show the person's saved theme, so after a paste they hold the values that were read. Changing a field and pressing Save saves the fields as the person's theme, so a theme edited by hand stays the person's own. A field left blank leaves that setting out of the theme. Each value is checked and refused exactly as a pasted one is, with spaces around it removed first. The fields are saved only when they differ from the saved theme, so picking a template or changing the Accent, Surface or Text picker saves as before, and a paste sent in the same save wins over the fields. The grouped fields and the font suggestions need no script, but the colour pickers need keystone_ui's colour picker script to take a typed colour.
202
+
203
+ Each change to a theme field is drawn on the whole page before saving, through the appearance editor script the install generator copies. The script sets the setting's `--ks-*` variables on the page's root element, taking the list of which setting sets which variables from the same theme roles list the palette style tag writes from, so the page looks as it will after Save. A colour also sets the hover colour the style tag derives from `primary`, `secondary` and `destructive`, and a dark value sets only the `-dark` variables, so it shows only where the page is drawn dark. Colours, corner radius, spacing, border width, letter spacing, fonts, font weights and the shadow are drawn this way, and the shadow is drawn only once all six shadow settings hold a value, as the style tag writes it. A value the browser cannot draw leaves the page as it was, and it is still sent and checked on Save. Leaving the section without saving removes every variable the script set, so the next page, a Turbo visit included, is drawn in the saved theme. The script saves nothing and sends no request, so Save works as before, and without the script the fields still save.
204
+
205
+ Beside the fields the section shows a preview of keystone_ui's own components: a card, a primary, a secondary and a danger button, a form with a text field and a select, a table, a line chart and a sidebar navigation list. The preview is drawn twice, once on a side marked light and once on a side marked dark, from sample data the gem holds. Each unsaved change the appearance editor script draws on the page also shows in the preview, so a dark value changes only the dark side, including while the page itself is drawn dark. A chart colour redraws the preview's line chart and a sidebar colour changes its navigation list. The preview names no font of its own and loads nothing from another site, so it draws in the fonts the theme sets. On a screen 64rem wide or wider the fields and the preview sit side by side. On a narrower screen, such as a phone, the section shows an Edit tab and a Preview tab from keystone_ui's tab switcher, and picking a tab shows its panel through the appearance editor script. The preview needs keystone_ui-styles 0.23.0 or later, whose dark styles leave a side marked light drawn light inside a dark page, and keystone_ui 0.47.0 or later, whose line chart takes light or dark from the side it is drawn on and redraws when the theme's variables change, and it needs keystone_ui's tab switcher and line chart scripts registered. The preview is shown only alongside the theme fields, so it is not shown while the account sets the colours for everyone.
206
+
207
+ The preset themes are option cards after the templates, each showing its light primary and secondary colours as swatches, and the person's saved preset is selected. Picking a preset card fills the theme fields with that preset's values, through the appearance editor script, which draws them on the whole page and the preview before saving, as it draws a field changed by hand. Once a preset is saved the fields show its values. Theme fields sent unchanged, holding the picked or the saved preset's values, save the picked card as before. Changing a field after picking a preset saves the fields as the person's own theme in place of the preset. Without the script, picking a card and pressing Save still saves the preset. A Reset button beside Save fills every theme field, the page and the preview from the picked preset card, or from the saved theme when no preset card is picked, and saves nothing. A setting the saved theme leaves out is emptied, and the page draws it from the saved theme again.
208
+
209
+ Once a theme field differs from the saved theme, or the picked colour card, the Custom accent, surface or text picker, the picked Mode, the picked Look or, in the account's section, either Members choose switch differs from what the page opened with, or the paste box holds text, the appearance editor script asks before the change is lost. The page opens with the saved colour card, colours, Mode, Look and switches selected, after a refused save as well, so picking another and then the saved one again asks nothing. A paste box that is empty or holds only spaces sends nothing to save, so it asks nothing. Following a link out of the section holds the Turbo visit and opens a question on the page, from keystone_ui's modal, offering Leave without saving and Stay. Leave without saving carries on to the page the link was going to, and Stay closes the question. Because the question is part of the page, it shows in a Hotwire Native web view, where Turbo asks the page before it hands a link to the app. Closing or reloading the page asks the browser to show its own leave-page warning, which a Hotwire Native web view does not show. The native back button and tab bar of a Hotwire Native app leave the page without asking it, so they leave with no question, and so does the browser's back button. Saving, resetting to the saved theme, or changing nothing leaves with no question. The question is part of every Appearance section, the person's and the account's, including one that offers no colours. The question needs keystone_ui's modal script registered as `modal`.
210
+
211
+ After the theme fields an Export text area shows the fields' current values, saved or not, as a `:root` block with every light value and a `.dark` block with every dark value, in shadcn/ui's variable names, which is the shape the paste box reads. The appearance editor script writes it when the section opens and again on each change, in the browser, so it carries unsaved edits. The text area is read-only and has no name, so Save does not send it. A Copy button beside it copies the export through keystone_ui's clipboard script with no request to the server. Where the browser refuses to copy, as a Hotwire Native web view may, the button says to select the text, and the text area can be selected and copied by hand. A value holding a semicolon or a curly brace is left out, so it cannot end its block or add a setting. An exported theme pasted back into the paste box and saved keeps every value it held. Copying needs keystone_ui's clipboard script registered. The export is not offered in keystone's own `--ks-*` variable names.
183
212
 
184
213
  The `colours` key follows the account layouts above. While an account turns off members-choose for it, the section says the account sets the colours for everyone and offers no colours, and a save that sends colours anyway is refused with a message and saves nothing.
185
214
 
@@ -211,7 +240,7 @@ An app that keeps people off their own looks sets `user_looks` to false. The app
211
240
 
212
241
  ## Account appearance
213
242
 
214
- An admin sets the account's colours and look in a settings_hub section. Who may open it is the app's decision, so register it behind a capability of the app's choosing:
243
+ An admin sets the account's colours and look in a settings_hub section. Who may open it is the app's decision, so register it behind a capability of the app's choosing. settings_hub refuses a capability the app does not define, so use the one the app already uses for its other account sections in place of `:manage_account`:
215
244
 
216
245
  ```ruby
217
246
  SettingsHub.section :account_appearance, area: :account, title: "Appearance",
@@ -220,11 +249,11 @@ SettingsHub.section :account_appearance, area: :account, title: "Appearance",
220
249
  runs: "KeystoneUi::Preferences::PickAccountAppearance"
221
250
  ```
222
251
 
223
- The section looks and behaves as keystone_ui-colors' account picker does. It offers Default, the five named templates and Custom with the three colour pickers, then the app's own look and every registered look, with the account's saved choices selected, or Default and the app's own look when it has none. Under them are two switches, one for whether members choose their own colours and one for whether members choose their own look. Both are on until an admin turns them off.
252
+ The section looks and behaves as keystone_ui-colors' account picker does. It offers Default, the five named templates, the six preset themes and Custom with the three colour pickers and the paste box the person's section has, then the app's own look and every registered look, with the account's saved choices selected, or Default and the app's own look when it has none. Under them are two switches, one for whether members choose their own colours and one for whether members choose their own look. Both are on until an admin turns them off. The theme fields come last, grouped into Colors, Typography and Other as in the person's section. The section is the same theme editor as the person's. Each change to a field and each picked preset card is drawn on the whole page before saving. The preview sits beside the fields on a wide screen and under Edit and Preview tabs on a phone. A Reset button beside Save fills the fields from the picked preset card, or from the account's saved theme, and saves nothing. The Export text area and its Copy button carry the fields' current values. Leaving the section without saving draws the next page in the admin's own saved theme. While the app turns off account colours the section shows no preview, no tabs and no Reset button.
224
253
 
225
- Saving keeps the account's colours under the `colours` key, as `{ "template_name": "forest" }` or `{ "accent": "#e11d48", "surface": "#f5e6c8", "text": "#3b2f1e" }`, and its look under the `look` key, with each switch in that row's `members_choose` column. Saving Default keeps `{ "template_name": "default" }`, and saving the app's own look keeps an empty look, so neither removes the row its switch is on. The colours and look pass the same checks as a person's, and a template, colour or look that fails one is refused with a message, and nothing is saved. A save with no account is refused too.
254
+ Saving keeps the account's colours under the `colours` key, as `{ "template_name": "forest" }`, `{ "preset_name": "harbor" }`, `{ "accent": "#e11d48", "surface": "#f5e6c8", "text": "#3b2f1e" }` or a pasted or hand-edited theme, and its look under the `look` key, with each switch in that row's `members_choose` column. Saving Default keeps `{ "template_name": "default" }`, and saving the app's own look keeps an empty look, so neither removes the row its switch is on. The colours, a pasted theme, the theme fields and the look pass the same checks as a person's, the theme fields are saved only when they differ from the account's saved theme or the picked or saved preset, and a template, preset, colour, theme value or look that fails one is refused with a message, and nothing is saved. A save with no account is refused too.
226
255
 
227
- While the colours switch is off, every member sees the account's colours, and their appearance section says the account sets the colours and offers no colour choice. While the look switch is off, every member sees the account's look, and their appearance section offers no look choice. A look a member sends then is ignored, and the rest of the save is kept. While the look switch is on, a member who chose a look keeps it, and a member with none sees the account's.
256
+ A member with no colours of their own sees the account's colours and theme. While the colours switch is off, every member sees the account's colours and theme, and their appearance section says the account sets the colours and offers no colour choice. While the look switch is off, every member sees the account's look, and their appearance section offers no look choice. A look a member sends then is ignored, and the rest of the save is kept. While the look switch is on, a member who chose a look keeps it, and a member with none sees the account's.
228
257
 
229
258
  An app that keeps accounts off colours sets `account_colors` to false. Neither section then offers a colour choice or the colours switch, every page is drawn in the four configured defaults, and colours sent to either section are refused with a message. An app that keeps accounts off looks sets `account_looks` to false. The account's section then offers no look choice and no look switch, a look sent to it is ignored, and a saved account look is not applied.
230
259
 
@@ -242,26 +271,24 @@ A choice made with keystone_ui's theme toggle in that browser still sets light o
242
271
 
243
272
  ## Moving off keystone_ui-colors
244
273
 
245
- An app that saved colours, modes and looks with keystone_ui-colors keeps them by following these steps in this order. An app that has never installed keystone_ui-preferences adds it to the Gemfile and runs its install generator before step 1.
274
+ An app that saved colours, modes and looks with keystone_ui-colors keeps them by following these steps in this order. An app that has never installed keystone_ui-preferences runs its install generator at step 5 instead of the update generator.
246
275
 
247
- 1. Update keystone_ui-preferences.
248
- 2. Run its update generator, which copies the migration below into `db/migrate`.
249
- 3. Remove keystone_ui-colors from the Gemfile and run `bundle install`.
250
- 4. Change every `KeystoneUi::Colors` name the app uses to its replacement. keystone_ui-colors' README lists each name and what replaces it under [Moving to keystone_ui-preferences](https://github.com/DYB-Development/keystone_ui-colors#moving-to-keystone_ui-preferences).
251
- 5. Register the person's appearance section and the account's appearance section, the account's behind `capability: :manage_account`, as [Appearance](#appearance) and [Account appearance](#account-appearance) show.
252
- 6. Call `super` from any `after_settings_change` the app defines.
253
- 7. Run `bin/rails db:migrate`.
276
+ 1. Set keystone_ui-preferences to `~> 0.7` and remove keystone_ui-colors from the Gemfile, then run `bundle install`.
277
+ 2. Change every `KeystoneUi::Colors` name the app uses to its replacement, and move any settings from a keystone_ui-colors initializer into a keystone_ui-preferences initializer. keystone_ui-colors' README lists each name and what replaces it under [Moving to keystone_ui-preferences](https://github.com/DYB-Development/keystone_ui-colors#moving-to-keystone_ui-preferences).
278
+ 3. Register the person's appearance section and the account's appearance section, as [Appearance](#appearance) and [Account appearance](#account-appearance) show. Register the account's behind the capability the app already uses for its other account sections.
279
+ 4. Call `super` from any `after_settings_change` the app defines.
280
+ 5. Run its update generator, which copies the migration below into `db/migrate`.
281
+ 6. Run `bin/rails db:migrate`.
254
282
 
255
283
  ```bash
256
- bundle update keystone_ui-preferences
257
- bin/rails generate keystone_ui:preferences:update
258
- # remove keystone_ui-colors from the Gemfile
284
+ # set keystone_ui-preferences to ~> 0.7 and remove keystone_ui-colors from the Gemfile
259
285
  bundle install
260
- # change each KeystoneUi::Colors name, register both appearance sections, call super from after_settings_change
286
+ # change each KeystoneUi::Colors name, move the initializer settings, register both appearance sections, call super from after_settings_change
287
+ bin/rails generate keystone_ui:preferences:update
261
288
  bin/rails db:migrate
262
289
  ```
263
290
 
264
- Boot stops with `KeystoneUi::Preferences::ColorsCheck::Error` while keystone_ui-colors is loaded, and the message names keystone_ui-colors as the gem to remove and the update generator as the step to run first. `bin/rails db:migrate` boots the app, so keystone_ui-colors comes out of the Gemfile before the migration runs, and the generator runs before keystone_ui-colors comes out so the copy migration is in `db/migrate` when it does. An initializer, route, controller or helper that still names `KeystoneUi::Colors`, such as a `KeystoneUi::Colors.configure` block, a route mounting `KeystoneUi::Colors::Engine`, `include KeystoneUi::Colors::CurrentPalette` or `helper KeystoneUi::Colors::PaletteHelper`, also stops the app from booting, so every name is changed before the migration runs.
291
+ Boot stops with `KeystoneUi::Preferences::ColorsCheck::Error` while keystone_ui-colors is loaded, and the message names keystone_ui-colors as the gem to remove. The update generator and `bin/rails db:migrate` both boot the app, so keystone_ui-colors comes out of the Gemfile before either runs. An initializer, route, controller or helper that still names `KeystoneUi::Colors`, such as a `KeystoneUi::Colors.configure` block, a route mounting `KeystoneUi::Colors::Engine`, `include KeystoneUi::Colors::CurrentPalette` or `helper KeystoneUi::Colors::PaletteHelper`, also stops the app from booting, so every name is changed before the generator runs.
265
292
 
266
293
  The generator copies a migration that reads every row of `keystone_ui_colors_theme_preferences` and writes up to three rows for the same owner:
267
294
 
@@ -29,8 +29,8 @@ module KeystoneUi
29
29
  end
30
30
 
31
31
  def keystone_palette_style_tag
32
- colours = keystone_appearance_choice.colours
33
- helpers.content_tag(:style, PaletteCss.new(**colours).to_s)
32
+ choice = keystone_appearance_choice
33
+ helpers.content_tag(:style, [ ThemeCss.new(palette: choice.colours).to_s, choice.theme_css ].compact.join("\n"))
34
34
  end
35
35
 
36
36
  def keystone_theme_mode
@@ -0,0 +1,235 @@
1
+ import { Controller } from "@hotwired/stimulus"
2
+
3
+ const THEME_FIELD = /^theme\[([^\]]+)\]\[(light|dark)\]$/
4
+ const ENDS_DECLARATION = /[;{}]/
5
+ const QUICK_CHOICES = "[name='template_name'], [name='accent'], [name='surface'], [name='text'], [name='mode'], [name='look'], [name='members_choose'], [name='members_choose_look']"
6
+ const PROPERTY_FOR_KIND = { colour: "color", length: "width", letter_spacing: "letter-spacing", font_list: "font-family", weight: "font-weight" }
7
+ const SHADOW_SETTINGS = ["shadow-offset-x", "shadow-offset-y", "shadow-blur", "shadow-spread", "shadow-color", "shadow-opacity"]
8
+ const SHADOWS = ["--ks-shadow-surface", "--ks-shadow-overlay", "--ks-shadow-menu"]
9
+
10
+ export default class extends Controller {
11
+ static targets = ["accentPicker", "surfacePicker", "textPicker", "customRadio", "templateLabel"]
12
+
13
+ #setVariables = new Set()
14
+ #loadedChoices = []
15
+ #heldUrl = null
16
+ #leaveAllowed = false
17
+
18
+ connect() {
19
+ this.#loadedChoices = this.#quickChoices()
20
+ this.colorPickerTargets().forEach(picker => picker.addEventListener("change", () => this.customColorChanged()))
21
+ this.#writeExport()
22
+ this.#drawUnsavedFields()
23
+ }
24
+
25
+ confirmLeave(event) {
26
+ if (!this.#hasUnsavedChanges()) return
27
+
28
+ event.preventDefault()
29
+ this.#heldUrl = event.detail.url
30
+ this.element.querySelector("[data-leave-question] [data-modal-target='backdrop']").classList.remove("hidden")
31
+ }
32
+
33
+ warnBeforeUnload(event) {
34
+ if (this.#hasUnsavedChanges()) event.preventDefault()
35
+ }
36
+
37
+ save() {
38
+ this.#leaveAllowed = true
39
+ }
40
+
41
+ leave() {
42
+ this.#leaveAllowed = true
43
+ this.element.ownerDocument.defaultView.Turbo.visit(this.#heldUrl)
44
+ }
45
+
46
+ disconnect() {
47
+ this.#setVariables.forEach(variable => this.#rootStyle().removeProperty(variable))
48
+ this.#setVariables.clear()
49
+ }
50
+
51
+ apply({ target: { name, value } }) {
52
+ this.#writeExport()
53
+ const field = name.match(THEME_FIELD)
54
+ if (!field) return
55
+
56
+ const [, role, side] = field
57
+ if (SHADOW_SETTINGS.includes(role)) return this.#drawShadow()
58
+
59
+ const { kind, variables, hover } = this.#roles()[role]
60
+ const suffix = side === "dark" ? "-dark" : ""
61
+ if (value === "") {
62
+ [...variables, hover].filter(Boolean).forEach(variable => this.#remove(`${variable}${suffix}`))
63
+ return
64
+ }
65
+ if (!CSS.supports(PROPERTY_FOR_KIND[kind], value)) return
66
+
67
+ variables.forEach(variable => this.#set(`${variable}${suffix}`, value))
68
+ if (hover) this.#set(`${hover}${suffix}`, `color-mix(in oklab, ${value} 85%, white)`)
69
+ }
70
+
71
+ colorPickerTargets() {
72
+ return [
73
+ this.hasAccentPickerTarget && this.accentPickerTarget,
74
+ this.hasSurfacePickerTarget && this.surfacePickerTarget,
75
+ this.hasTextPickerTarget && this.textPickerTarget
76
+ ].filter(Boolean)
77
+ }
78
+
79
+ selectTemplate(event) {
80
+ const input = event.currentTarget
81
+ const label = input.closest("[data-template]")
82
+ const accentHex = input.dataset.accentHex
83
+ const surfaceHex = input.dataset.surfaceHex
84
+ const textHex = input.dataset.textHex
85
+
86
+ this.setPickerValue(this.accentPickerTarget, accentHex)
87
+ this.setPickerValue(this.surfacePickerTarget, surfaceHex)
88
+ this.setPickerValue(this.textPickerTarget, textHex)
89
+
90
+ this.highlightTemplate(label.dataset.template)
91
+ }
92
+
93
+ selectPreset(event) {
94
+ const input = event.currentTarget
95
+ const theme = JSON.parse(input.dataset.theme)
96
+
97
+ Object.entries(theme).forEach(([role, sides]) => {
98
+ Object.entries(sides).forEach(([side, value]) => this.setThemeField(`theme[${role}][${side}]`, value))
99
+ })
100
+
101
+ this.highlightTemplate(input.closest("[data-template]").dataset.template)
102
+ }
103
+
104
+ reset() {
105
+ const preset = this.element.querySelector("input[name='template_name'][data-theme]:checked")
106
+ const theme = JSON.parse(preset ? preset.dataset.theme : this.element.querySelector("[data-saved-theme]").dataset.savedTheme)
107
+
108
+ this.element.querySelectorAll("[name^='theme[']").forEach(({ name }) => {
109
+ const [, role, side] = name.match(THEME_FIELD)
110
+ this.setThemeField(name, theme[role]?.[side] ?? "")
111
+ })
112
+ }
113
+
114
+ setThemeField(name, value) {
115
+ const field = this.element.querySelector(`[name="${name}"]`)
116
+ if (!field) return
117
+
118
+ const picker = field.closest("[data-controller~='color-picker']")
119
+ if (picker) {
120
+ this.setPickerValue(picker, value)
121
+ } else {
122
+ field.value = value
123
+ }
124
+ field.dispatchEvent(new Event("change", { bubbles: true }))
125
+ }
126
+
127
+ showPanel({ detail: { index } }) {
128
+ this.element.querySelectorAll("[data-editor-panel]").forEach((panel, place) => panel.toggleAttribute("data-shown", place === index))
129
+ }
130
+
131
+ customColorChanged() {
132
+ if (this.hasCustomRadioTarget) this.customRadioTarget.checked = true
133
+ this.highlightTemplate("custom")
134
+ }
135
+
136
+ highlightTemplate(selected) {
137
+ this.templateLabelTargets.forEach(label => {
138
+ const border = label.querySelector("span")
139
+ if (label.dataset.template === selected) {
140
+ border.classList.remove("border-transparent")
141
+ border.classList.add("border-accent-500")
142
+ } else {
143
+ border.classList.remove("border-accent-500")
144
+ border.classList.add("border-transparent")
145
+ }
146
+ })
147
+ }
148
+
149
+ setPickerValue(wrapper, hex) {
150
+ const input = wrapper.querySelector("input[type='hidden']")
151
+ const swatch = wrapper.querySelector("[data-color-picker-target='swatch']")
152
+ const hexLabel = wrapper.querySelector("[data-color-picker-target='hexLabel']")
153
+ const text = wrapper.querySelector("[data-color-picker-target='text']")
154
+
155
+ if (input) input.value = hex
156
+ if (swatch) swatch.style.backgroundColor = hex
157
+ if (hexLabel) hexLabel.textContent = hex
158
+ if (text) text.value = hex
159
+ }
160
+
161
+ #writeExport() {
162
+ const exported = this.element.querySelector("[data-theme-export]")
163
+ if (!exported) return
164
+
165
+ const roles = Object.keys(this.#roles())
166
+ const block = side => roles.flatMap(role => {
167
+ const field = this.element.querySelector(`[name="theme[${role}][${side}]"]`)
168
+ return field?.value && !ENDS_DECLARATION.test(field.value) ? [` --${role}: ${field.value};\n`] : []
169
+ }).join("")
170
+ const css = `:root {\n${block("light")}}\n\n.dark {\n${block("dark")}}\n`
171
+ exported.value = css
172
+ this.element.querySelector("[data-controller~='clipboard']").dataset.clipboardText = css
173
+ }
174
+
175
+ #drawShadow() {
176
+ const settings = SHADOW_SETTINGS.map(setting => this.element.querySelector(`[name="theme[${setting}][light]"]`)?.value)
177
+ const [x, y, blur, spread, colour, opacity] = settings
178
+ const shadow = `${x} ${y} ${blur} ${spread} color-mix(in srgb, ${colour} calc(${opacity} * 100%), transparent)`
179
+ if (settings.every(Boolean) && CSS.supports("box-shadow", shadow)) {
180
+ SHADOWS.forEach(variable => this.#set(variable, shadow))
181
+ } else {
182
+ SHADOWS.forEach(variable => this.#remove(variable))
183
+ }
184
+ }
185
+
186
+ #drawUnsavedFields() {
187
+ this.#unsavedFields().forEach(field => this.apply({ target: field }))
188
+ }
189
+
190
+ #unsavedFields() {
191
+ const saved = this.#savedTheme()
192
+ return [...this.element.querySelectorAll("[name^='theme[']")].filter(field => {
193
+ const [, role, side] = field.name.match(THEME_FIELD)
194
+ return field.value !== (saved[role]?.[side] ?? "")
195
+ })
196
+ }
197
+
198
+ #savedTheme() {
199
+ return JSON.parse(this.element.querySelector("[data-saved-theme]")?.dataset.savedTheme ?? "{}")
200
+ }
201
+
202
+ #hasUnsavedChanges() {
203
+ return !this.#leaveAllowed && (this.#unsavedFields().length > 0 || this.#quickChoicesChanged() || this.#pasteTyped())
204
+ }
205
+
206
+ #quickChoicesChanged() {
207
+ return this.#quickChoices().some((choice, place) => choice !== this.#loadedChoices[place])
208
+ }
209
+
210
+ #pasteTyped() {
211
+ return [...this.element.querySelectorAll("[name='pasted_theme']")].some(({ value }) => value.trim() !== "")
212
+ }
213
+
214
+ #quickChoices() {
215
+ return [...this.element.querySelectorAll(QUICK_CHOICES)].map(field => (["radio", "checkbox"].includes(field.type) ? field.checked : field.value))
216
+ }
217
+
218
+ #roles() {
219
+ return JSON.parse(this.element.querySelector("[data-theme-roles]").dataset.themeRoles)
220
+ }
221
+
222
+ #set(variable, value) {
223
+ this.#rootStyle().setProperty(variable, value)
224
+ this.#setVariables.add(variable)
225
+ }
226
+
227
+ #remove(variable) {
228
+ this.#rootStyle().removeProperty(variable)
229
+ this.#setVariables.delete(variable)
230
+ }
231
+
232
+ #rootStyle() {
233
+ return this.element.ownerDocument.documentElement.style
234
+ }
235
+ }
@@ -8,9 +8,10 @@ module KeystoneUi
8
8
  PALETTE_NAME = /\A[a-z][a-z0-9_]*\z/
9
9
  WHITE = "#ffffff"
10
10
 
11
- def initialize(person:, account:)
11
+ def initialize(person:, account:, own_look: nil)
12
12
  @person = person
13
13
  @account = account
14
+ @own_look = own_look
14
15
  end
15
16
 
16
17
  def colours
@@ -35,6 +36,15 @@ module KeystoneUi
35
36
  !colours[:background].casecmp?(WHITE)
36
37
  end
37
38
 
39
+ def theme_css
40
+ return unless configuration.account_colors
41
+ return preset_css if saved.key?("preset_name")
42
+ return unless saved.key?("theme")
43
+ return refused_theme_css if refused_theme
44
+
45
+ Rails.cache.fetch([ colours_choice.preference.cache_key_with_version, "theme_css", ThemeCss::VERSION, own_look? ]) { written_theme }
46
+ end
47
+
38
48
  private
39
49
 
40
50
  def chosen_colours
@@ -42,6 +52,8 @@ module KeystoneUi
42
52
  return default_colours if saved["template_name"] == DEFAULT_TEMPLATE
43
53
  return template_colours if template_offered?
44
54
  return fallback_colours if saved["template_name"].present?
55
+ return account_colours if saved["preset_name"].present? && !preset_offered?
56
+ return account_colours if refused_theme
45
57
 
46
58
  surface = catalogue_colour("surface", KeystoneUi::Looks::Palettes::SURFACES) || configuration.default_surface
47
59
  {
@@ -52,6 +64,51 @@ module KeystoneUi
52
64
  }
53
65
  end
54
66
 
67
+ def preset_css
68
+ unless preset_offered?
69
+ warn_missing("preset", saved["preset_name"])
70
+ return account_theme_css
71
+ end
72
+
73
+ Rails.cache.fetch([ "preset_css", saved["preset_name"], KeystoneUi::Looks::VERSION, ThemeCss::VERSION, own_look? ]) { written(KeystoneUi::Looks::Themes[saved["preset_name"]][:theme]) }
74
+ end
75
+
76
+ def preset_offered?
77
+ KeystoneUi::Looks::Themes.names.map(&:to_s).include?(saved["preset_name"].to_s)
78
+ end
79
+
80
+ def refused_theme_css
81
+ row = colours_choice.preference
82
+ Rails.logger.warn("keystone_ui-preferences: #{row.owner_type} #{row.owner_id} saved a theme #{refused_theme}")
83
+ account_theme_css
84
+ end
85
+
86
+ def refused_theme
87
+ return unless saved.key?("theme")
88
+ return "that is not a set of roles, so it fails the theme check" unless theme_shaped?(saved["theme"])
89
+
90
+ @refused_theme ||= CheckedTheme.new(saved["theme"]).failing_setting&.then { |setting| "whose --#{setting} setting fails the theme check" }
91
+ end
92
+
93
+ def written_theme
94
+ written(saved["theme"])
95
+ end
96
+
97
+ def written(theme)
98
+ checked = CheckedTheme.new(theme)
99
+ ThemeCss.new(checked.value["theme"], own_look: own_look?).to_s unless checked.refusal
100
+ end
101
+
102
+ def own_look?
103
+ return @own_look unless @own_look.nil?
104
+
105
+ @person.present? && person_chooses_look? && KeystoneUi.configuration.looks.key?(saved_look(@person))
106
+ end
107
+
108
+ def theme_shaped?(theme)
109
+ theme.is_a?(Hash) && theme.values.all?(Hash)
110
+ end
111
+
55
112
  def saved_look(owner)
56
113
  LayoutChoice.new(person: owner, account: nil, component_key: "look").value.to_h["look"]
57
114
  end
@@ -72,6 +129,14 @@ module KeystoneUi
72
129
 
73
130
  def fallback_colours
74
131
  warn_missing("template", saved["template_name"])
132
+ account_colours
133
+ end
134
+
135
+ def account_theme_css
136
+ AppearanceChoice.new(person: @account, account: nil, own_look: own_look?).theme_css unless @account.nil? || colours_choice.preference.owned_by?(@account)
137
+ end
138
+
139
+ def account_colours
75
140
  return default_colours if @account.nil? || colours_choice.preference.owned_by?(@account)
76
141
 
77
142
  AppearanceChoice.new(person: @account, account: nil).colours