Skip to content

Commit

Permalink
feat(file-uploader): Updated @uploadcare/blocks to @uploadcare/file-u…
Browse files Browse the repository at this point in the history
…ploader
  • Loading branch information
egordidenko committed Sep 18, 2024
1 parent 114d177 commit 25d4053
Show file tree
Hide file tree
Showing 15 changed files with 76 additions and 69 deletions.
10 changes: 6 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ run_django:

update_bundled_static:
blocks_version=$$(DJANGO_SETTINGS_MODULE=tests.test_project.settings poetry run python -c "from pyuploadcare.dj.conf import DEFAULT_CONFIG; print(DEFAULT_CONFIG['widget']['version'])"); \
curl "https://cdn.jsdelivr.net/npm/@uploadcare/blocks@$${blocks_version}/web/blocks.min.js" -o pyuploadcare/dj/static/uploadcare/blocks.min.js; \
curl "https://cdn.jsdelivr.net/npm/@uploadcare/blocks@$${blocks_version}/web/lr-file-uploader-inline.min.css" -o pyuploadcare/dj/static/uploadcare/lr-file-uploader-inline.min.css; \
curl "https://cdn.jsdelivr.net/npm/@uploadcare/blocks@$${blocks_version}/web/lr-file-uploader-minimal.min.css" -o pyuploadcare/dj/static/uploadcare/lr-file-uploader-minimal.min.css; \
curl "https://cdn.jsdelivr.net/npm/@uploadcare/blocks@$${blocks_version}/web/lr-file-uploader-regular.min.css" -o pyuploadcare/dj/static/uploadcare/lr-file-uploader-regular.min.css
curl "https://cdn.jsdelivr.net/npm/@uploadcare/file-uploader@$${blocks_version}/web/file-uploader.min.js" -o pyuploadcare/dj/static/uploadcare/file-uploader.min.js; \
curl "https://cdn.jsdelivr.net/npm/@uploadcare/file-uploader@$${blocks_version}/web/uc-file-uploader-inline.min.css" -o pyuploadcare/dj/static/uploadcare/uc-file-uploader-inline.min.css; \
curl "https://cdn.jsdelivr.net/npm/@uploadcare/file-uploader@$${blocks_version}/web/uc-file-uploader-minimal.min.css" -o pyuploadcare/dj/static/uploadcare/uc-file-uploader-minimal.min.css; \
curl "https://cdn.jsdelivr.net/npm/@uploadcare/file-uploader@$${blocks_version}/web/uc-file-uploader-regular.min.css" -o pyuploadcare/dj/static/uploadcare/uc-file-uploader-regular.min.css



21 changes: 13 additions & 8 deletions docs/django-widget.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,22 @@ PyUploadcare takes assets from CDN by default, e.g.:

.. code-block:: html

<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/@uploadcare/file-uploader@1/web/uc-file-uploader-regular.min.css"
>


<script type="module">
import * as LR from "https://cdn.jsdelivr.net/npm/@uploadcare/[email protected]/web/blocks.min.js";
LR.registerBlocks(LR);
import * as UC from "https://cdn.jsdelivr.net/npm/@uploadcare/file-uploader@1/web/file-uploader.min.js";
UC.defineComponents(UC);
</script>

<!-- ... -->

<lr-file-uploader-inline
css-src="https://cdn.jsdelivr.net/npm/@uploadcare/[email protected]/web/lr-file-uploader-regular.min.css"
<uc-file-uploader-inline
ctx-name="my-uploader"
></lr-file-uploader-inline>
></uc-file-uploader-inline>

If you don't want to use hosted assets you have to turn off this feature:

Expand All @@ -91,9 +96,9 @@ widget url:
"widget": {
"override_js_url": "http://path.to/your/blocks.js",
"override_css_url": {
"regular": "http://path.to/your/lr-file-uploader-regular.css",
"inline": "http://path.to/your/lr-file-uploader-inline.css",
"minimal": "http://path.to/your/lr-file-uploader-minimal.css",
"regular": "http://path.to/your/uc-file-uploader-regular.css",
"inline": "http://path.to/your/uc-file-uploader-inline.css",
"minimal": "http://path.to/your/uc-file-uploader-minimal.css",
},
},
}
Expand Down
2 changes: 1 addition & 1 deletion docs/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -128,5 +128,5 @@ In version 5.0, we introduce a new `file uploader`_, which is now the default fo
Additionally, please take note that some settings have been renamed in this update. For example, ``UPLOADCARE["widget_version"]`` has been changed to ``UPLOADCARE["legacy_widget"]["version"]``. You can find the full list of these changes in the `changelog for version 5.0.0`_.

.. _file uploader: https://uploadcare.com/docs/file-uploader/
.. _@uploadcare/blocks: https://www.npmjs.com/package/@uploadcare/blocks
.. _@uploadcare/file-uploader: https://www.npmjs.com/package/@uploadcare/file-uploader
.. _changelog for version 5.0.0: https://github.com/uploadcare/pyuploadcare/blob/main/HISTORY.md#500---2023-12-28
10 changes: 5 additions & 5 deletions pyuploadcare/dj/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class SettingsType(typing_extensions.TypedDict):
"use_legacy_widget": False,
"use_hosted_assets": True,
"widget": {
"version": "0.36.0",
"version": "1",
"variant": "regular",
"build": "min",
"options": {},
Expand Down Expand Up @@ -131,10 +131,10 @@ def get_legacy_widget_js_url() -> str:

def get_widget_js_url() -> str:
widget_config = config["widget"]
filename = "blocks.{0}.js".format(widget_config["build"]).replace(
filename = "file-uploader.{0}.min.js".format(widget_config["build"]).replace(
"..", "."
)
hosted_url = "https://cdn.jsdelivr.net/npm/@uploadcare/blocks@{version}/web/{filename}".format(
hosted_url = "https://cdn.jsdelivr.net/npm/@uploadcare/file-uploader@{version}/web/{filename}".format(
version=widget_config["version"], filename=filename
)
local_url = "uploadcare/{filename}".format(filename=filename)
Expand All @@ -149,10 +149,10 @@ def get_widget_js_url() -> str:

def get_widget_css_url(variant: WidgetVariantType) -> str:
widget_config = config["widget"]
filename = "lr-file-uploader-{0}.{1}.css".format(
filename = "uc-file-uploader-{0}.{1}.min.css".format(
variant, widget_config["build"]
).replace("..", ".")
hosted_url = "https://cdn.jsdelivr.net/npm/@uploadcare/blocks@{version}/web/{filename}".format(
hosted_url = "https://cdn.jsdelivr.net/npm/@uploadcare/file-uploader@{version}/web/{filename}".format(
version=widget_config["version"], filename=filename
)
local_url = "uploadcare/{filename}".format(filename=filename)
Expand Down
28 changes: 0 additions & 28 deletions pyuploadcare/dj/static/uploadcare/blocks.min.js

This file was deleted.

29 changes: 29 additions & 0 deletions pyuploadcare/dj/static/uploadcare/file-uploader.min.js

Large diffs are not rendered by default.

This file was deleted.

This file was deleted.

This file was deleted.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions pyuploadcare/dj/templates/uploadcare/forms/widgets/file.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,32 @@
{% endif %}

<div style="position: relative; display: flex;">
<link rel="stylesheet" href="{{ uploadcare_css }}" >

<script type="module">
import * as LR from "{{ uploadcare_js }}";
LR.registerBlocks(LR);
import * as UC from "{{ uploadcare_js }}";
UC.defineComponents(UC);
</script>

<lr-config
<uc-config
ctx-name="{{ name }}"
pubkey="{{ pub_key }}"
{% for k, v in options.items %}
{{ k|escape }}="{{ v|escape }}"{% endfor %}
></lr-config>
></uc-config>

<lr-upload-ctx-provider
<uc-upload-ctx-provider
id="uploaderctx_{{ name }}"
ctx-name="{{ name }}"
></lr-upload-ctx-provider>
></uc-upload-ctx-provider>

<lr-file-uploader-{{ variant }}
css-src="{{ uploadcare_css }}"
<uc-file-uploader-{{ variant }}
ctx-name="{{ name }}"
>
<lr-form-input
<uc-form-input
ctx-name="{{ name }}"
></lr-form-input>
</lr-file-uploader-{{ variant }}>
></uc-form-input>
</uc-file-uploader-{{ variant }}>


</div>
Expand Down
11 changes: 5 additions & 6 deletions tests/dj/test_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def setUp(self):
self._original_widget = config["widget"]
config["use_hosted_assets"] = True
config["widget"] = {
"version": "latest",
"version": "1",
"variant": "inline",
"build": "",
"options": {},
Expand All @@ -71,12 +71,12 @@ def test_hosted_js_url(self):
config["use_hosted_assets"] = True
self.assertEqual(
get_widget_js_url(),
"https://cdn.jsdelivr.net/npm/@uploadcare/blocks@latest/web/blocks.js",
"https://cdn.jsdelivr.net/npm/@uploadcare/file-uploader@1/web/file-uploader.min.js",
)

def test_local_js_url(self):
config["use_hosted_assets"] = False
self.assertEqual(get_widget_js_url(), "uploadcare/blocks.js")
self.assertEqual(get_widget_js_url(), "uploadcare/file-uploader.min.js")

def test_override_js_url(self):
config["widget"]["override_js_url"] = "https://example.com/blocks.js"
Expand All @@ -86,15 +86,14 @@ def test_hosted_css_url(self):
config["use_hosted_assets"] = True
self.assertEqual(
get_widget_css_url("minimal"),
"https://cdn.jsdelivr.net/npm/@uploadcare/blocks@latest"
+ "/web/lr-file-uploader-minimal.css",
"https://cdn.jsdelivr.net/npm/@uploadcare/file-uploader@1/web/uc-file-uploader-minimal.min.css"
)

def test_local_css_url(self):
config["use_hosted_assets"] = False
self.assertEqual(
get_widget_css_url("minimal"),
"uploadcare/lr-file-uploader-minimal.css",
"uploadcare/uc-file-uploader-minimal.min.css",
)

def test_override_css_url(self):
Expand Down
6 changes: 3 additions & 3 deletions tests/dj/test_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ class SomeForm(forms.Form):
f = SomeForm(label_suffix="")
self.assertFalse(f["ff"].field.legacy_widget)
ff_str = str(f["ff"])
self.assertIn("LR.registerBlocks(LR);", ff_str)
self.assertIn("<lr-config\n", ff_str)
self.assertIn("UC.defineComponents(UC);", ff_str)
self.assertIn("<uc-config\n", ff_str)
self.assertIn('pubkey="asdf"', ff_str)
self.assertIn('ctx-name="ff"', ff_str)

Expand Down Expand Up @@ -75,7 +75,7 @@ class SomeForm(forms.Form):
f = SomeForm(label_suffix="")
self.assertFalse(f["ff"].field.legacy_widget)
ff_str = str(f["ff"])
self.assertIn("LR.registerBlocks(LR);", ff_str)
self.assertIn("UC.defineComponents(UC);", ff_str)
self.assertIn('source-list="local"', ff_str)


Expand Down

0 comments on commit 25d4053

Please sign in to comment.